-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: OutOfMemoryError/Not closing pre-bound Hibernate Session...
PostPosted: Wed Oct 19, 2005 1:28 am 
Newbie

Joined: Mon Sep 26, 2005 8:43 am
Posts: 16
I am in the process of Upgrading Hibernate from version 2.1.6 to 3.0.5. Well as we are making use of Spring Framework, we are also upgrading Spring from version 1.0.1 to 1.2.4 (as it supports Hibernate 3). What I have observed is: After certain DB calls the application is not working and showing java.lang.OutOfMemoryError. When I observe the stack trace it shows that the Session objects are not being closed:
Code:
2005-10-19 10:40:16,689 DEBUG [com.abc.persistence.MyHibernateTemplate] Found thread-bound Session for HibernateTemplate
2005-10-19 10:40:19,513 DEBUG [com.abc.persistence.MyHibernateTemplate] Eagerly flushing Hibernate session
2005-10-19 10:40:19,513 DEBUG [com.abc.persistence.MyHibernateTemplate] Not closing pre-bound Hibernate Session after HibernateTemplate


The code for MyHibernateTemplate is as follows:

Code:
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Session;

import org.springframework.orm.hibernate3.HibernateTemplate;

public class MyHibernateTemplate extends HibernateTemplate
{
   /**
    * @see org.springframework.orm.hibernate3.HibernateAccessor#flushIfNecessary(org.hibernate.Session, boolean)
    */
   public void flushIfNecessary(Session session, boolean existingTransaction)
         throws HibernateException
   {
      // Overriden to prevent flushing if Session.flushMode is NEVER     
      boolean assumeReadOnlyTransaction = existingTransaction && session.getFlushMode().equals(FlushMode.NEVER);
     
      if( !assumeReadOnlyTransaction )
      {
         super.flushIfNecessary(session, existingTransaction);
      }
   }
}


Well, I am not very sure whether this problem is due to Spring or Hibernate. But it used to work in the earlier Spring & Hibernate. Plz. let me know what's going wrong.

_________________
--Beejal


Top
 Profile  
 
 Post subject: 2c
PostPosted: Wed Oct 19, 2005 2:52 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
my 2c :do not use HibernateTemplate, configure Spring to inject H callbacks and wrap your object into Spring's transaction context support.
http://www.onjava.com/lpt/a/5854
http://www.springframework.org/docs/reference/orm.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: Re: 2c
PostPosted: Wed Oct 19, 2005 5:06 am 
Newbie

Joined: Mon Sep 26, 2005 8:43 am
Posts: 16
Hello Konstantin,
kgignatyev wrote:
my 2c :do not use HibernateTemplate, configure Spring to inject H callbacks

Can you please let me know the reason for the above statement. The reason behind this question is : We are making use of HibernateTemplate throughout the application and if we act on your suggestion it would lead to a very big change (Which should be considered as last option only).


Quote:
and wrap your object into Spring's transaction context support.


We already have implemented AOP feature of Spring (org.springframework.transaction.interceptor.TransactionInterceptor) to wrap certain objects with Spring Transaction context.


Quote:

Have you provided these links for guiding regarding Making use of Spring Transaction or do u want to convey some more information also by this links?

_________________
--Beejal


Top
 Profile  
 
 Post subject: clarifications
PostPosted: Wed Oct 19, 2005 11:07 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Quote:
Can you please let me know the reason for the above statement. The reason behind this question is : We are making use of HibernateTemplate throughout the application and if we act on your suggestion it would lead to a very big change (Which should be considered as last option only).

http://houseofhaug.net/blog/archives/20 ... tes-spring

I do not thing you will need that much of refactoring especially because you already have the transaction interceptor in place. Basically instead of using H template you will have your DAO objects as simple POJOs with a setter method for H session and then you will use the session directly for everything you need. I would say that the change is trivial.


And the two links I mentioned:
Spring documentation link: as a reference for various spring provided methods of dealing with Hibernate.
Article link: detailed example of using H in Spring as I suggest using it.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.