-
Feb 16th, 2012, 09:11 PM
#1
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:
open session
read something
begin transaction 1
write something
commit transaction 1
begin transaction 2
write something
commit transaction 2
close session
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
#2
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
#3
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
#4
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....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules