java.lang.IllegalStateException: No transactional EntityManager available
You must annotate the method with the @Transactional
annotation:
@Transactional
public void fooBar() {
// Exception from this line
Session session = getEntityManager().unwrap(Session.class);
...
}
And, if necessary e.g. when using plain Spring framework, enable the Spring @Transactional
processing with the following declaration in your Spring's xml configuration file (where txManager
is the ID of your manager):
<tx:annotation-driven transaction-manager="txManager" />
Try this ?
entityManager=entityManager.getEntityManagerFactory().createEntityManager();
Session session = (Session) entityManager.unwrap(Session.class);
None of this was working for me, I finally found that the issue was that I was making my method @Transactional instead I needed the class to be @Transactional