Feb 16th, 2012, 09:11 PM
Hibernate 4 open session AOP
I've read the Spring 3.1 reference that plain Hibernate style, sessionFactory.getCurrentSession() is recommended. The question is when to open and close the session. I know @Transactional does that, but it can't handle the following scenario:
begin transaction 1
commit transaction 1
begin transaction 2
commit transaction 2
If the whole method is annotated with @Transactional, I can't separate 2 transactions. Is there any AOP utility to manage only the session (but not transaction) around method invocation? OpenSessionInViewInterceptor does not fit because my application is not a webapp.
Feb 17th, 2012, 01:17 AM
I suggest a read of the reference guide especially the transaction chapter.
You can still do manual transaction management by using either a TransactionTemplate or interact directly with a PlatformTransactionManager.
Feb 17th, 2012, 02:02 AM
Thanks Marten. My focus is not on transaction. I would like to know except @Transactional, is there any AOP utility to open a session and bind it to the session factory's current session?
Feb 17th, 2012, 03:08 AM
Why would you want to open an new session whereas a single session is perfectly capable of managing multiple transactions?!
But to directly answer your question no there isn't....