*
The moose likes Object Relational Mapping and the fly likes Sessions Exceeded using Oracle 10g, Hibernate, Spring and Tomcat 5.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Sessions Exceeded using Oracle 10g, Hibernate, Spring and Tomcat 5.5 " Watch "Sessions Exceeded using Oracle 10g, Hibernate, Spring and Tomcat 5.5 " New topic
Author

Sessions Exceeded using Oracle 10g, Hibernate, Spring and Tomcat 5.5

Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Hi,

I am having an issue in a webapp written in Java, it uses hibernate3 with the default connection pool, the spring framework, Oracle 10g (10.2.0.4) Database and Tomcat 5.5.20 as Application Server. When users do action in the app, the number of sessions with database are dramatically incremented, one user logged to the app can generate 4 or 5 sessions with the database. When more users are using the application, the number of sessions could grow to 50 or 60 up to the limit of asigned sessions to the application in the database, in that moment a DataAccessException is throw an all users logged in the application are logged out.

I really dont know what can i do, but i need a solution immediatly, or i will lose my job!!!... noo, its a lie, hehehe... but its really important solve it.

Best Regards,

Juan Manuel
Francois Nadeau
Ranch Hand

Joined: Apr 09, 2009
Posts: 46
Hello Juan,

Have you verified that all hibernate sessions are closed (or at least disconnected) after being used?

Cheers,

Francois


[url]http://FrancoisNadeau.com[/url]
Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Francois Nadeau wrote:Hello Juan,

Have you verified that all hibernate sessions are closed (or at least disconnected) after being used?

Cheers,

Francois


How can I verify that??,

Regards,

JM
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

By looking at the code where you close the Session?

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Paul Sturrock wrote:By looking at the code where you close the Session?


Because i did not wrote the code of this app, i will try to tell you what can i see. We have a GenericDao, that inherits from "HibernateDaoSupport", the rest of the daos inherits from the GenericDao and all of them do the same in their methods, an example:



I could not see any getSession().close(); even in the genericDao.

Regards,

JM
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

HibernateDaoSupport sounds like a Spring class. Is it? There should be something actively closing the sessions. Depending on the pattern your code uses this will either be explicit in the code, or use another mechanism (such as the end of a JTA transaction) to close it for you. If neither of these are there then nothing closes the sessions, hence the error you are seeing.

Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Paul Sturrock wrote:HibernateDaoSupport sounds like a Spring class. Is it? There should be something actively closing the sessions. Depending on the pattern your code uses this will either be explicit in the code, or use another mechanism (such as the end of a JTA transaction) to close it for you. If neither of these are there then nothing closes the sessions, hence the error you are seeing.



Yes, its a spring class..., i dont know what to think!!!...

Regards,

JM
Benjamin Winterberg
Ranch Hand

Joined: Sep 19, 2007
Posts: 36
Normally Springs HibernateDaoSupport manages the hibernate session by itself. The internally used HibernateTemplate opens the hibernate session and closes the session on transaction#commit(). Maybe there's some misconfiguration in your project which brokes springs session management?

Also HibernateDaoSupport isnt the right thing to implement DAOs anymore. Take a look at this blog entry for a detailed explanation:
http://bwinterberg.blogspot.com/2009/08/comparison-implementing-hibernate-daos.html


You can inspect the HibernateStatistics to check if all opened sessions are correctly closed (see SessionFactory#getStatistics()).


Hibernate DAOs with Spring | Separation of Concerns | Eclipse Code Templates | more...
Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Benjamin Winterberg wrote:Normally Springs HibernateDaoSupport manages the hibernate session by itself. The internally used HibernateTemplate opens the hibernate session and closes the session on transaction#commit(). Maybe there's some misconfiguration in your project which brokes springs session management?

Also HibernateDaoSupport isnt the right thing to implement DAOs anymore. Take a look at this blog entry for a detailed explanation:
http://bwinterberg.blogspot.com/2009/08/comparison-implementing-hibernate-daos.html


You can inspect the HibernateStatistics to check if all opened sessions are correctly closed (see SessionFactory#getStatistics()).


We will try adding a finally block invoking the method "releaseSession(session)" after the catch of the DataAccessException. If it works, i will post it!...

Best Regards,

JM
Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Juan Manuel Diaz wrote:
Benjamin Winterberg wrote:Normally Springs HibernateDaoSupport manages the hibernate session by itself. The internally used HibernateTemplate opens the hibernate session and closes the session on transaction#commit(). Maybe there's some misconfiguration in your project which brokes springs session management?

Also HibernateDaoSupport isnt the right thing to implement DAOs anymore. Take a look at this blog entry for a detailed explanation:
http://bwinterberg.blogspot.com/2009/08/comparison-implementing-hibernate-daos.html


You can inspect the HibernateStatistics to check if all opened sessions are correctly closed (see SessionFactory#getStatistics()).


We will try adding a finally block invoking the method "releaseSession(session)" after the catch of the DataAccessException. If it works, i will post it!...

Best Regards,

JM


It doesnt work, more ideas???,

JM
Francois Nadeau
Ranch Hand

Joined: Apr 09, 2009
Posts: 46
Hi Juan,

Yes, the code you show us would cause connection problems. You need to keep a reference to the session, and then close it. Calling getSession().close() will not close the session that you are using, but instead will close a new session which you did not use.

Your code should look as follows:



Cheers.

Francois
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

With Spring you should not need to explicitly close the session, it is being managed by Spring itself. As Benjamin pointed out earlier if this is not happening then there is some mistake in your Spring configuration. I'd look there rather than trying to code round the mistake.
Juan Manuel Diaz
Ranch Hand

Joined: Mar 23, 2009
Posts: 53
Paul Sturrock wrote:With Spring you should not need to explicitly close the session, it is being managed by Spring itself. As Benjamin pointed out earlier if this is not happening then there is some mistake in your Spring configuration. I'd look there rather than trying to code round the mistake.


The issue was solved, it was a misconfiguration in the xml of jbpm framework!!!.....

Best Regards and thanks to all,

JM
 
 
subject: Sessions Exceeded using Oracle 10g, Hibernate, Spring and Tomcat 5.5