-->
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.  [ 1 post ] 
Author Message
 Post subject: Session closing even with on_close! (LazyInitialization)
PostPosted: Sat Jan 09, 2010 8:55 am 
Newbie

Joined: Sat Jan 09, 2010 8:41 am
Posts: 2
Ello guys,

I'm getting a LazyInitializationException while trying to access a ManyToMany mapped object as Lazy fetch mode in the View. I tried to implement the OpenSessionInView (https://www.hibernate.org/43.html), with an Interceptor and a Servlet Filter but no one works.

Follows JBoss log:
Quote:
2010-01-09 09:33:45,593 TRACE [org.hibernate.event.def.AbstractFlushingEventListener] (http-0.0.0.0-8080-1) executing flush
2010-01-09 09:33:45,593 TRACE [org.hibernate.jdbc.ConnectionManager] (http-0.0.0.0-8080-1) registering flush begin
2010-01-09 09:33:45,593 TRACE [org.hibernate.jdbc.ConnectionManager] (http-0.0.0.0-8080-1) registering flush end
2010-01-09 09:33:45,593 TRACE [org.hibernate.event.def.AbstractFlushingEventListener] (http-0.0.0.0-8080-1) post flush
2010-01-09 09:33:45,593 TRACE [org.hibernate.jdbc.JDBCContext] (http-0.0.0.0-8080-1) before transaction completion
2010-01-09 09:33:45,593 TRACE [org.hibernate.impl.SessionImpl] (http-0.0.0.0-8080-1) before transaction completion
2010-01-09 09:33:45,593 DEBUG [org.hibernate.transaction.JDBCTransaction] (http-0.0.0.0-8080-1) committed JDBC Connection
2010-01-09 09:33:45,593 TRACE [org.hibernate.jdbc.JDBCContext] (http-0.0.0.0-8080-1) after transaction completion
2010-01-09 09:33:45,593 DEBUG [org.hibernate.jdbc.ConnectionManager] (http-0.0.0.0-8080-1) transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2010-01-09 09:33:45,593 TRACE [org.hibernate.impl.SessionImpl] (http-0.0.0.0-8080-1) after transaction completion
2010-01-09 09:33:45,593 TRACE [org.hibernate.impl.SessionImpl] (http-0.0.0.0-8080-1) automatically closing session
2010-01-09 09:33:45,593 TRACE [org.hibernate.impl.SessionImpl] (http-0.0.0.0-8080-1) closing session
2010-01-09 09:33:45,593 TRACE [org.hibernate.jdbc.ConnectionManager] (http-0.0.0.0-8080-1) performing cleanup
2010-01-09 09:33:45,593 DEBUG [org.hibernate.jdbc.ConnectionManager] (http-0.0.0.0-8080-1) releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2010-01-09 09:33:45,593 TRACE [org.hibernate.connection.DriverManagerConnectionProvider] (http-0.0.0.0-8080-1) returning connection to pool, pool size: 1
2010-01-09 09:33:45,593 TRACE [org.hibernate.jdbc.JDBCContext] (http-0.0.0.0-8080-1) after transaction completion
2010-01-09 09:33:45,593 DEBUG [org.hibernate.jdbc.ConnectionManager] (http-0.0.0.0-8080-1) transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2010-01-09 09:33:45,593 TRACE [org.hibernate.impl.SessionImpl] (http-0.0.0.0-8080-1) after transaction completion
2010-01-09 09:33:45,593 TRACE [org.hibernate.context.ThreadLocalSessionContext] (http-0.0.0.0-8080-1) allowing proxied method [hashCode] to proceed to real session
2010-01-09 09:33:45,593 TRACE [net.m21xx.integra.domain.base.BaseDAO] (http-0.0.0.0-8080-1) Session now is 25411043
2010-01-09 09:33:45,609 TRACE [net.m21xx.integra.utils.HibernateUtil] (http-0.0.0.0-8080-1) Getting current SessionFactory
2010-01-09 09:33:45,609 DEBUG [org.hibernate.impl.SessionImpl] (http-0.0.0.0-8080-1) opened session at timestamp: 12630404256
2010-01-09 09:33:45,609 TRACE [org.hibernate.context.ThreadLocalSessionContext] (http-0.0.0.0-8080-1) allowing proxied method [hashCode] to proceed to real session
2010-01-09 09:33:45,609 TRACE [net.m21xx.integra.domain.base.BaseDAO] (http-0.0.0.0-8080-1) Session before was 23602427
2010-01-09 09:33:45,609 TRACE [org.hibernate.context.ThreadLocalSessionContext] (http-0.0.0.0-8080-1) allowing method [beginTransaction] in non-transacted context
2010-01-09 09:33:45,609 TRACE [org.hibernate.context.ThreadLocalSessionContext] (http-0.0.0.0-8080-1) allowing proxied method [beginTransaction] to proceed to real session
2010-01-09 09:33:45,609 DEBUG [org.hibernate.transaction.JDBCTransaction] (http-0.0.0.0-8080-1) begin
2010-01-09 09:33:45,609 DEBUG [org.hibernate.jdbc.ConnectionManager] (http-0.0.0.0-8080-1) opening JDBC connection


Follows part of the mapping:
Code:
   <class name="GruposVO" table="grupos">
      <id name="id">
         <generator class="native" />
      </id>      
      <property name="nome" />
      <property name="descricao" />
      <bag name="usuarios" lazy="true" table="usuarios_grupos">
         <key column="grupoId" />
         <many-to-many column="usuarioId" class="UsuariosVO" />
      </bag>
   </class>
   
   <class name="UsuariosVO" table="usuarios">
      <id name="id">
         <generator class="native" />
      </id>
      <property name="nome" column="usuario" />
      <property name="senha" />   
      <property name="habilitado" />
      <property name="dataCriacao" column="tsDataCriacao" />
      <property name="ultimoLogin" column="tsUltimoLogin" />
      <bag name="grupos" lazy="true" table="usuarios_grupos">
         <key column="usuarioId" />
         <many-to-many column="grupoId" class="GruposVO" />
      </bag>      
      <bag name="sessoes" lazy="true" inverse="true">
         <key column="usuarioId" />
         <one-to-many class="SessoesVO" />
      </bag>      
   </class>



Follows the hibernate.cfg.xml:
Code:
    <session-factory>
        <property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/integra</property>
       
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.connection.password"></property>
       
        <property name="hibernate.connection.pool_size">1</property>
        <property name="hibernate.connection.autocommit">false</property>
        <property name="hibernate.connection.release_mode">on_close</property>
       
        <property name="hibernate.default_schema">integra</property>       
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
       
<!--
      <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
        <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
-->
        <property name="hibernate.transaction.auto_close_session">false</property>
        <property name="hibernate.transaction.flush_before_completion">false</property>
       
        <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
       
        <property name="hibernate.current_session_context_class">thread</property>
       
        <property name="hibernate.show_sql">false</property>

        <mapping resource="mapeamento.hbm.xml"/>
    </session-factory>


Follows the servletFilter:
Code:
   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException
   {
      logger.debug("Filtro executando...");
      
      Session lSession = null;
      
      try
      {
         logger.trace("Opening Hibernate session");
         lSession = HibernateUtil.getSessionFactory().openSession();
         logger.trace("Session now is " + lSession.hashCode());

         chain.doFilter(request, response);
      }
      finally
      {
         logger.trace("Session now is " + lSession.hashCode());
         if (lSession.isOpen())
         {
            lSession.close();
         }
         else
         {
            logger.debug("AVISO: Sessao ja foi fechada!");
         }
         logger.debug("Filtro executado com sucesso.");
      }      
   }


Any idea how to force the session to stay active?


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

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.