Results 1 to 5 of 5

Thread: Memory leak org/hibernate/engine/StatefulPersistenceContext

  1. #1
    Join Date
    Feb 2011
    Posts
    2

    Default Memory leak org/hibernate/engine/StatefulPersistenceContext

    We have a lot of OutOfMemory error in our application
    After analyzing the JVM, we supsect some MemoryLeak due to org/hibernate/engine/StatefulPersistenceContext.
    We are using:
    -Websphere 6.1 + Spring Hibernate 3.0.1.RELEASE-A + Hibernate 3.2.7.ga

    SessionFactory:class="org.springframework.orm.hibe rnate3.LocalSessionFactoryBean"
    transactionManager:class="org.springframework.tran saction.jta.JtaTransactionManager"
    in our DAO:
    public class xxxDaoImpl extends BaseDao {
    public void createXXX(Object obj) throws DataAccessException {
    this.getHibernateTemplate().saveOrUpdate(obj);
    etc....

    I turned the debug on and we got something like:
    2011-02-10 13:40:34,024 | DEBUG | org.springframework.orm.hibernate3.SessionFactoryU tils - Opening Hibernate Session
    2011-02-10 13:40:34,024 | DEBUG | org.springframework.orm.hibernate3.SessionFactoryU tils - Registering Spring transaction synchronization for new Hibernate Session
    2011-02-10 13:40:34,024 | DEBUG | org.springframework.orm.hibernate3.HibernateTempla te - Found thread-bound Session for HibernateTemplate
    2011-02-10 13:40:34,029 | DEBUG | org.springframework.orm.hibernate3.HibernateTempla te - Not closing pre-bound Hibernate Session after HibernateTemplate
    etc.....
    2011-02-10 13:40:34,045 | DEBUG | org.springframework.orm.hibernate3.SessionFactoryU tils - Closing Hibernate Session
    2011-02-10 13:40:34,045 | DEBUG | org.springframework.orm.hibernate3.SessionFactoryU tils - Opening Hibernate Session


    Can you help me please on how to optimize spring/hibernate sessions?
    How can i flush/close session if Spring JTA manager is not doing the job?

    Do you have any ideas?

    Thanks
    Last edited by David M; Feb 10th, 2011 at 08:52 AM.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,630

    Default

    Please use [ code][/code ] tags when posting code/stacktraces etc. that way it remains readable.

    HibernateTemplate isn't closing the session because it was already bound... The logging says nothing about the tx manager, you also see the closing of the hibernate session. In general the outofmemories are caused by either
    1. Improper transactionmanagement or setup
    2. Reading/processing a lot of data without calling flush and clear which eats up the memory

    Also please post your configuration as that might be informative, especially the hibernate and tx stuff.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Feb 2011
    Posts
    2

    Default

    Thanks for your reply

    1. Improper transactionmanagement or setup
    - How can i be sure that i have a proper transactionmanagement?

    2. Reading/processing a lot of data without calling flush and clear which eats up the memory
    How can i flush/clear hibernate session, as i am not referring this session in any place of my code.
    I am using HibernateTemplate, and this one get the session from SessionFactory



    SPRING 3.0.1.RELEASE-A
    HIBERNATE 3.2.7.GA

    Code:
    my AppContext.xml file:
    <bean id="mySessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property
    name="mappingResources"><list><value>com/xxx/yyy/model/domain/hibernate/Account.hbm.xml</value></list></property>
    <property name="hibernateProperties">
    <props>
    <prop
    key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
    <prop key="hibernate.show_sql">false</prop>
    </props>
    </property>
    <property name="dataSource">
    <ref bean="myDataSource" />
    </property>
    </bean>
    <bean id="myDao"
    class="com.xxx.yyy.model.domain.dao.hibernate.MyDaoImpl" >
    <property name="sessionFactory"><ref bean="mySessionFactory" />
    </property>
    </bean>
    <bean id="transactionManager"
    class="org.springframework.transaction.jta.JtaTransactionManager"/>
    <bean id="myServiceTarget"
    class="com.xxx.yyy.service.admin.MyServiceImpl">
    <property name="myDao"><ref bean="myDao"/></property>
    </bean>
    <bean id="myService"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager" />
    </property>
    <property name="target"><ref local="myServiceTarget" /></property>
    <property name="transactionAttributes">
    <props>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
    </props>
    </property>
    </bean>
    my classes:
    Code:
    public abstract class MyBaseDao extends HibernateDaoSupport {}
    
    public class MyDaoImpl extends MyBaseDao {
      public void save(MyObject obj) throws DataAccessException {
          this.getHibernateTemplate().saveOrUpdate(obj);
      }
    }
    Last edited by David M; Feb 12th, 2011 at 07:44 AM.

  4. #4
    Join Date
    Sep 2010
    Posts
    25

    Default

    we have the same issue on our application

    entityEntries Map in StatefulPersistenceContext slowly grow and do out of memory

    did you solve your issue ?
    Last edited by etrier; Nov 5th, 2012 at 09:51 AM.

  5. #5
    Join Date
    Sep 2012
    Posts
    3

    Default

    any one able to solve this issue?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •