java.lang.reflect.InvocationTargetException: null

  1. 0

    Hibernate: Session is Closed

    Stack Overflow | 5 months ago | kenundrumz2100
    java.lang.reflect.InvocationTargetException: null
  2. 0

    I am using the ThreadLocalContext transaction with hibernate. This application was wrote with hibernate 2.1.7 and work well, but decide migrate to hibernate 3.1.1. I Extended the class ThreadLocalContext to overwrite the next methods: protected ConnectionReleaseMode getConnectionReleaseMode() { return ConnectionReleaseMode.ON_CLOSE; } protected boolean isAutoCloseEnabled() { return false; } protected Session buildOrObtainSession() { Session s = (Session) threadSession.get(); try { if((s!=null && !s.isOpen() )) s = null; if(s!=null){ if(s.isDirty() || !s.isOpen() || !s.isConnected()){ s.close(); s = null; } } if (s == null) { log.debug("Session is null - take new Session"); s = this.factory.openSession(); threadSession.set(s); } bind(s); } catch (HibernateException ex) { log.error("Error take a new Session - " + ex.getMessage()); throw new DCMHibernateException(ex); } return s; } This i do because in the API javadoc, in class ThreadLocalContext say let you a handler more time session in scope. The application init, do some stuff with database throw hibernate but when arrive time to save the Object com.mjoy.dcmbase.entities.Sesion (Bussines Object) that contain an attribute must be serialize, throws the next stackTrace: 27-01-2006 13:34:20 DEBUG [SerializationHelper.serialize:141] Starting serialization of object [{opcionesUsuario={D=com.mjoy.dcmbase.entities.DescTono@1509443, A=com.mjoy.dcmbase.entities.DescTono@1eaf705, F=com.mjoy.dcmbase.entities.DescTono@51ddd2, H=com.mjoy.dcmbase.entities.DcmObject@192ee25, C=com.mjoy.dcmbase.entities.DescTono@16e2b70, B=com.mjoy.dcmbase.entities.DescTono@4aad7f, G=com.mjoy.dcmbase.entities.DescTono@1a5678, E=com.mjoy.dcmbase.entities.DescTono@1f07360}, paginado=[com.mjoy.dcmbase.entities.DescTono@afcd0c, com.mjoy.dcmbase.entities.DescTono@ed3007, com.mjoy.dcmbase.entities.DescTono@1b0caf], ranking=com.mjoy.dcmbase.entities.Ranking@39b99d}] org.hibernate.SessionException: Session is closed! at org.hibernate.impl.AbstractSessionImpl.errorIfClosed( at org.hibernate.impl.SessionImpl.getPersistenceContext( at org.hibernate.proxy.BasicLazyInitializer.getReplacement( at org.hibernate.proxy.BasicLazyInitializer.invoke( at org.hibernate.proxy.CGLIBLazyInitializer.intercept( at com.mjoy.dcmbase.entities.Medio$$EnhancerByCGLIB$$52ca026d.writeReplace(<generated>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at at at at at at at at java.util.HashMap.writeObject( at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at at at at at at org.hibernate.util.SerializationHelper.serialize( at org.hibernate.util.SerializationHelper.serialize( at org.hibernate.type.SerializableType.toBytes( at org.hibernate.type.SerializableType.deepCopyNotNull( at org.hibernate.type.MutableType.deepCopy( at org.hibernate.type.TypeFactory.deepCopy( at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate( at org.hibernate.event.def.AbstractSaveEventListener.performSave( at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId( at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId( at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient( at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate( at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate( at org.hibernate.impl.SessionImpl.fireSaveOrUpdate( at org.hibernate.impl.SessionImpl.saveOrUpdate( at org.hibernate.impl.SessionImpl.saveOrUpdate( at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke( at $Proxy0.saveOrUpdate(Unknown Source) at com.mjoy.dcmbase.persistence.PersistenceManager.saveOrUpdate( at com.mjoy.dcmbase.entities.Sesion.saveOrUpdate( at com.mjoy.dcm.handler.RankingLogic.empiezaTransaccion( at com.mjoy.dcm.handler.VentaRankingHandler.execute( at com.mjoy.dcm.servlets.DCM.doAction( at com.mjoy.dcm.servlets.DCM.doGet( at javax.servlet.http.HttpServlet.service( at javax.servlet.http.HttpServlet.service( at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( at org.apache.catalina.core.ApplicationFilterChain.doFilter( at org.apache.catalina.core.StandardWrapperValve.invoke( at org.apache.catalina.core.StandardValveContext.invokeNext( at org.apache.catalina.core.StandardPipeline.invoke( at org.apache.catalina.core.StandardContextValve.invokeInternal( at org.apache.catalina.core.StandardContextValve.invoke( at org.apache.catalina.core.StandardValveContext.invokeNext( at org.apache.catalina.core.StandardPipeline.invoke( at org.apache.catalina.core.StandardHostValve.invoke( at org.apache.catalina.core.StandardValveContext.invokeNext( at org.apache.catalina.valves.ErrorReportValve.invoke( at org.apache.catalina.core.StandardValveContext.invokeNext( at org.apache.catalina.core.StandardPipeline.invoke( at org.apache.catalina.core.StandardEngineValve.invoke( at org.apache.catalina.core.StandardValveContext.invokeNext( at org.apache.catalina.core.StandardPipeline.invoke( at org.apache.catalina.core.ContainerBase.invoke( at org.apache.coyote.tomcat5.CoyoteAdapter.service( at org.apache.coyote.http11.Http11Processor.process( at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection( at at org.apache.tomcat.util.threads.ThreadPool$ at 27-01-2006 13:34:22 DEBUG [PersistenceManager.saveOrUpdate:250] Error save or updating object - com.mjoy.dcmbase.entities.Sesion Session is closed! 27-01-2006 13:34:22 ERROR [Sesion.saveOrUpdate:223] Error saving sesion org.hibernate.SessionException: Session is closed! I post in the hibernate Forum but nobody can help me. below i write the code with mapping Sesion class and with the code when call the saveOrUpdate(obj) and throw excpetion describe above -Mapping class Sesion: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" ""> <hibernate-mapping > <class name="com.mjoy.dcmbase.entities.Sesion" table="sesion" > <id name="id" column="id" type="java.lang.Long" unsaved-value="null" > <generator class="native"> <!-- To add non XDoclet generator parameters, create a file named hibernate-generator-params-Sesion.xml containing the additional parameters and place it in your merge dir. --> </generator> </id> <property name="atributos" type="serializable" update="true" insert="true" column="datos" not-null="false" unique="false" /> <property name="linea" type="java.lang.Long" update="true" insert="true" column="linea" not-null="false" unique="false" /> <property name="status" type="java.lang.Integer" update="true" insert="true" column="status" not-null="false" unique="false" /> <property name="fecha" type="java.sql.Timestamp" update="true" insert="true" column="fecha" not-null="false" unique="false" /> <!-- To add non XDoclet property mappings, create a file named hibernate-properties-Sesion.xml containing the additional properties and place it in your merge dir. --> </class> <query name="ObtenerSesionLinea"><![CDATA[ from Sesion as s where s.linea like :linea ]]></query> </hibernate-mapping> -PersistenceManager Class: /** * * Este metodo tiene la siguiente funcionalidad: * * * @return */ private static SessionFactory instancia() { if (sessionFactory == null) { try { Configuration cfg = new Configuration(); log.debug("Iniciando configuraciĆ³n de hibernate"); cfg.configure(); sessionFactory = cfg.buildSessionFactory(); log.debug("Obtienendo SessionFactory "); } catch (HibernateException e) { log.error("Error initialize Session Factory hibernate :" + e.getMessage()); throw new DCMHibernateException(e.getMessage()); } catch (Exception e) { e.printStackTrace(); } } return sessionFactory; } /** * Cierra la cession; * */ public static Session getSession() { try { beginTransaction(); return instancia().getCurrentSession(); } catch (HibernateException ex) { log.error("Error closing session session - " + ex.getMessage()); throw new DCMHibernateException(ex); } } /** * Cierra la cession; * */ public static void closeSession() { try { Session s = getSession(); log.debug("Take session from thread"); if ((s != null)) { log.debug("Closing session"); s.close(); } } catch (HibernateException ex) { log.error("Error closing session session - " + ex.getMessage()); throw new DCMHibernateException(ex); } } /** * Inicia una transaccion * */ public static void beginTransaction() { try { Session s = instancia().getCurrentSession(); if(s.getTransaction()!=null && s.getTransaction().isActive()){ log.debug("Ya existe la transaccion y Esta Activa"); return; }else if(s.getTransaction()!=null){ log.debug("Ya existe transaccion pero no esta activa ........"); s.getTransaction().begin(); log.debug("Activando una nueva.........."); }else{ log.debug("Iniciando una nueva transaccion"); s.beginTransaction(); } } catch (HibernateException ex) { log.error("Error taking new transaction object - " + ex.getMessage()); throw new DCMHibernateException(ex); } } /** * Comitea las transacciones y cierra las sesiones * */ public static void commitTransaction() { Transaction tx = (Transaction) getSession().getTransaction(); log.debug("Trake transaction from thread"); try { if ((tx != null) && !tx.wasCommitted() && !tx.wasRolledBack()) { log.debug("Commiting transaction before closing"); tx.commit(); } } catch (HibernateException ex) { log.error("Error commiting transaction - " + ex.getMessage()); rollbackTransaction(); throw new DCMHibernateException(ex); } finally { log.debug("Close sesion transaction"); closeSession(); } } /** * Realiza un rollback si ocurre un error * */ public static void rollbackTransaction() { Transaction tx = (Transaction) getSession().getTransaction(); log.debug("Take transaction from thread"); try { if ((tx != null) && !tx.wasCommitted() && !tx.wasRolledBack()) { log.debug("Rollbak transaction"); tx.rollback(); } } catch (HibernateException ex) { log.error("Error rollback transaction - " + ex.getMessage()); throw new DCMHibernateException(ex); } finally { log.debug("Closing session"); closeSession(); } } /** * Actualiza o inserta un objeto en la base segun corresponda * @param obj */ public static void saveOrUpdate(Object obj) { try { log.debug("Save or Updating object - " + obj.getClass().getName()); Session s = getSession(); s.saveOrUpdate(obj); } catch (HibernateException e) { e.printStackTrace(); log.debug("Error save or updating object - " + obj.getClass().getName() + " \n " + e.getMessage()); throw new DCMHibernateException(e); } } Please i want to kwon if this is a bug or i had very poor ackwonlegde to version hibernate 3.1.1 handler session. I want to migrate to hibernate 3.1 but if this not work i return to 2.1.x version Thank you

    Hibernate JIRA | 1 decade ago | Juan Pablo Royo
    org.hibernate.SessionException: Session is closed!
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    SessionException on simple request

    Google Groups | 4 years ago | Torsten Zesch
    org.hibernate.SessionException: Session is closed!

    1 unregistered visitors
    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.hibernate.SessionException

      Session is closed!

      at org.hibernate.internal.AbstractSessionImpl.errorIfClosed()
    2. Hibernate
      1. org.hibernate.internal.AbstractSessionImpl.errorIfClosed(
      2. org.hibernate.internal.SessionImpl.createQuery(
      2 frames
    3. c.c.h
      1. c.c.h.t.h.EmHAO.getInfo(
      2. c.c.h.t.h.EmHAO.getAll(
      3. c.c.h.t.e.Em.getAll(
      3 frames