Hibernate session gets stuck when trying to flush data..
Hi Everyone,
Currently I am facing a problem in which Hibernate session is executing an SQL query against the Oracle database but then hibernate never gets control back and looks as if waiting for something forever.
I am using spring framework's hibernate support for database persistence.
I debugged the application and saw that Hibernate Session is executing a prepared statement underneath when it tries to flush data to the database and that's when everything gets hung.
My application creates multiple threads using JDK5 ThreadExecutor service and then, each thread invokes a new DAO instance which extends spring framework's HibernateSupport class. I am not sure why Hibernate acts this ways. All the threads are under the same transaction. So we have a kind of one transaction and one DAO per thread logic.
Any feedback will be highly appreciated.
Thanks.
Re: Hibernate session gets stuck when trying to flush data..
Quote:
Originally Posted by spring007
Hi Everyone,
My application creates multiple threads using JDK5 ThreadExecutor service and then, each thread invokes a new DAO instance which extends spring framework's HibernateSupport class.
Why do you create new dao`s? Why don`t you give a reference from a single dao, to all the threads?
Quote:
I am not sure why Hibernate acts this ways. All the threads are under the same transaction. So we have a kind of one transaction and one DAO per thread logic.
What do you mean with under the same transaction? If there is a big transactions started before the threads are started, and the threads do call to the dao, you have a serious problem. The HibernateSupport class retrieves the session (transaction) from some kind of threadlocal. But your threads in the threadpool don`t have this threadlocal set.
And how do your doa`s get a reference to the SessionFactory? Do you create that one every time you need it?
Transaction interceptor on own thread
We are using only one own thread. HTTP Request-Response threads put objects to a blocking queue, own thread takes them an works with them, and we are facing the same problems mentioned above.
Can you recommend some hints to create our own Transaction interceptor if it isn't possible to handle this problem (using declarative transactions in own threads) with the Spring's one?