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" />