HIbernate and CMT
Question
Lately I decided to implement in my project CMT transactions (jBoss5, Hibernate, jta postgres datasource). Everything is working fine except Hibernate.initialize() in my entities. It works in EJB beans but when trying to invoke initialize in entity getter I get "couldn't associate with session" exception. It worked just fine before implementing transactions. Anyone got accros same problem ?
Solution
Ok after days browsing the internet I found what is the problem. When u flag method as Supports transactions. It doesn't start them. If you retrieve objects out of transaction they are out of session and therefore u cannot initialize their properties...
OTHER TIPS
From the following reference page you may need to ensure the current properties are configured correctly for CMT
- set
hibernate.transaction.manager_lookup_class
to a lookup strategy for your Java EE container (see here for a list of JTA transaction managers) - set
hibernate.transaction.factory_class
toorg.hibernate.transaction.CMTTransactionFactory