0

as part of this question:

spring transactions in a spawned off thread

one solution im thinking of is grabbing my session factory as a normal bean and using that outside of spring transactions. then simply handle my transactions manually within my new thread.

my problem, is this possible? so far its not letting me do anything with the session factory outside of the spring transaction. if it is to detach it, how do i do that?

Community
  • 1
  • 1
scphantm
  • 4,293
  • 8
  • 43
  • 77
  • possible duplicate of [spring transactions in a spawned off thread](http://stackoverflow.com/questions/7915265/spring-transactions-in-a-spawned-off-thread) – matt b Oct 27 '11 at 13:27
  • actually, other parts of the app were in such bad shape that we decided to abandon the app and build a new one. – scphantm Nov 04 '11 at 18:17

1 Answers1

0

If you don't want to use the transaction manager you can call the below to create a session.

When you use transaction manager it does not mean that all Hibernate Sessions are closed when a transaction is committed! Only the Session that you obtained with sf.getCurrentSession() is flushed and closed automatically. If you decide to use sf.openSession() and manage the Session yourself, you have to flush() and close() it. So a less convenient alternative, without any "current" Session, is this:

Session session = sessionFactory.openSession();

This is explained in more detail here.

ManuPK
  • 11,623
  • 10
  • 57
  • 76