Using an EntityManager unwrapped method in a managed transaction bean
I am using Hibernate session derived from method em.unwrap(..)
. I couldn't find any information on whether I should release it after use. The operation is managed by the bean and the entity manager is injected using @Inject
.
boolean transactionSuccess = false;
try {
utx.begin();
final Session session = em.unwrap(Session.class);
transactionSuccess = true;
} finally {
commitOrRollback(transactionSuccess);
}
I am assuming that the object manager instance is container-managed. Since session is more or less the main implementation, should I release it? This is AutoCloseable
in the end.
the only relevant information I found was (but seems to be vanilla JPA): After using the pivot method on entitymanager, to get my own hibernate session, do I need to close both?
+3
source to share