<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=martinahrer" rel="nofollow">Martin Ahrer</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5236?redirect=false" rel="nofollow">SPR-5236</a></strong> and commented</p>
<p dir="auto">org.springframework.orm.jpa.vendor.HibernateJpaDialect.getSession should not try to cast directly to HibernateEntityManager since there is a chance that the entity manager passed in is just a proxy for the EntityManager interface!</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="protected Session getSession(EntityManager em) {
	return ((HibernateEntityManager) em).getSession();
}"><pre class="notranslate"><code class="notranslate">protected Session getSession(EntityManager em) {
	return ((HibernateEntityManager) em).getSession();
}
</code></pre></div>
<p dir="auto">This cast can be avoided (see below)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="protected Session getSession(EntityManager em) {
	return (Session) em.getDelegate();
}"><pre class="notranslate"><code class="notranslate">protected Session getSession(EntityManager em) {
	return (Session) em.getDelegate();
}
</code></pre></div>
<p dir="auto">I'm facing this problem while I'm trying to integrate Seam with Spring. Seam is in charge of managing the life time of the entity manager and passing it on to Spring using org.jboss.seam.ioc.spring.SeamManagedEntityManagerFactoryBean.</p>
<p dir="auto">Currently a work around is to subclass HibernateJpaDialect and implement getSession as shown!</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5.5</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398091487" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/9909" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/9909/hovercard" href="https://github.com/spring-projects/spring-framework/issues/9909">#9909</a> HibernateJpaDialect.getSession casting to HibernateEntityManager (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=gupabhi" rel="nofollow">Abhishek Gupta</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7782?redirect=false" rel="nofollow">SPR-7782</a></strong> and commented</p>
<p dir="auto">In production applications it is imperative that SQL statements and bind parameters be logged at a configurable level for support purposes.</p>
<p dir="auto">When using the JdbcTemplate spring does currently log both, but sql statements are logged at debug level and parameters are logged in the 'o.s.j.c.StatementCreatorUtils' class at trace level. It is impractical to keep trace level on in a critical (or any) production system - even for a single class. There are other non-important (or non-functional) debug/trace logs that might be in the class that are not required to be logged. Or new ones might be introduced in future versions.</p>
<p dir="auto">We would want the query/params to be logged at info level but again that might not be suitable for others, so ideally it should be something that is configurable.</p>
<p dir="auto">The work-around today is ugly, in that we wrap the JdbcTemplate just to be able to log the parameters. Ideally, if there could be a property in the JdbcTemplate that accepts the log level for functional logs (query, params in this case) it would be most helpful. Given that JdbcTemplate is now a total replacement for using any low level jdbc api, and is so popular, it makes sense to have this feature that will give users more control and contribute to the completeness of such a widely used Spring offering.</p>
<p dir="auto">I am happy to use any other solution you might have that addresses this use-case.</p>
<p dir="auto">Thanks,<br>
Abhi</p>
<p dir="auto">P.S. This really applies to other classes too like in the jdbc.object package</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.0.5</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398150504" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/14041" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/14041/hovercard" href="https://github.com/spring-projects/spring-framework/issues/14041">#14041</a> JdbcTemplate parameter and result logging (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398111146" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/12774" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/12774/hovercard" href="https://github.com/spring-projects/spring-framework/issues/12774">#12774</a> Revisit subsystem-oriented logging</li>
</ul>
<p dir="auto">6 votes, 14 watchers</p>