Announcement Announcement Module
Collapse
No announcement yet.
Memory leak org/hibernate/engine/StatefulPersistenceContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 09:52 AM.

  • #2
    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.

    Comment


    • #3
      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, 08:44 AM.

      Comment


      • #4
        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, 10:51 AM.

        Comment


        • #5
          any one able to solve this issue?

          Comment

          Working...
          X