tslusser wrote:
Hi Octopus,
Thank you for your reply. I would like to access the Hibernate Session in a consistent fashion for either Tx or NonTx operations. However if this is not possible using HibernateContext then I will use the SessionFactory directly from JNDI for operations without a Tx.
How do I enter a feature request such that HibernateContext will return a Session that is disconnected from a Tx? Are there any reasons that one would not want to do this?
Thanks,
Ted
Right, I'd like the same. There was a long discussion here with Steve after 1st iteration. Current version is trade-off which doesn't solve everything..
Let me briefly explain the problem.
The perfect solution would be to be able to call getSession() anywhere, get correct session and get it closed automatically when necessary.
To do this, container need to know hibernate session boundaries and be able to define context when getSession called.
In first version, session context was defined by either EJB interceptor or servlet filter which have to be applied to all components using hibernate. Even so it didn't always provide correct behavoiur.
For example: Servlet calls EJB which calls another EJB. All of them call getSession(). How container can find out that all these calls are from the same context and it needs to provide them the same session. Another problem is when to close session.
Since nobody yet clearly described correct behaviour in cases like this starting with version 2 hibernite session binds to current transaction. It is perfect for transactional context because hibernate session matches transaction lifecycle. But it doesn't solve the issue with non-TX contexts.
Any ideas of how it can be done would be appreciated.