Messsage d'erreur "session closed"
Bonjour a tous, j'ai un problème de session closed sous hibernate
Lorsque j'utilise le debbuger, il me dir que la session que j'envoi est ouverte, c'est quand on passe le return qu'elle passe à closed.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
org.hibernate.SessionException: Session is closed!
at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1346)
at fr.visionitgroup.centreon.dao.DaoCnxImpl.clear(DaoCnxImpl.java:89)
at fr.visionitgroup.centreon.utils.ApplicationContextUtils.clearDao(ApplicationContextUtils.java:283)
at fr.visionitgroup.centreon.utils.ApplicationContextUtils.initDao(ApplicationContextUtils.java:164)
at fr.visionitgroup.centreon.utils.ApplicationContextUtils.<init>(ApplicationContextUtils.java:120)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) |
mon util :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| package fr.visionitgroup.centreon.dao;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
/**
* @author sbuisson
*
*/
public class HibernateUtil
{
private static SessionFactory sessionFactory = null;
static
{
try
{
sessionFactory = (new AnnotationConfiguration().configure("hibernate.cfg.xml").buildSessionFactory());
}
catch (final HibernateException ex)
{
ex.printStackTrace();
throw new RuntimeException("Problème de configuration : " + ex.getMessage(), ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession()
throws HibernateException
{
Session s = (Session)session.get();
// Ouvre une nouvelle Session, si ce Thread n'en a aucune
if (s == null)
{
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession()
throws HibernateException
{
final Session s = (Session)session.get();
session.set(null);
if (s != null)
{
s.close();
}
}
} |
mon conf
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="">
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.EmbeddedDriver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:derby:CentreonDB;create=true;update=true;</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
<property name="hibernate.default_schema">CENTREON</property>
<!-- <property name="connection.pool_size">15</property> -->
<mapping class="fr.visionitgroup.centreon.model.CnxWebLogic"/>
<mapping class="fr.visionitgroup.centreon.model.ConnexionImpl"/>
<mapping class="fr.visionitgroup.centreon.model.Jmx.MetricJmx"/>
<mapping class="fr.visionitgroup.centreon.model.MetricAccessible"/>
<mapping class="fr.visionitgroup.centreon.model.MetricDB"/>
<mapping class="fr.visionitgroup.centreon.model.Jmx.MetricJMXExist"/>
<mapping class="fr.visionitgroup.centreon.model.Jmx.MetricJMXAddition"/>
<mapping class="fr.visionitgroup.centreon.model.Jmx.MetricJMXCount"/>
<mapping class="fr.visionitgroup.centreon.model.oracle.MetricOracle"/>
<mapping class="fr.visionitgroup.centreon.model.ValueDB"/>
<mapping class="fr.visionitgroup.centreon.model.oracle.OracleCnx"/>
</session-factory>
</hibernate-configuration> |
mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
Session session = HibernateUtil.currentSession();
while (!session.isOpen())
{
session = HibernateUtil.currentSession();
}
final Transaction tx = session.beginTransaction();
final Metric m = new DaoMetricImpl().findMetricByCnx(connexion.getId());
session.createSQLQuery("delete from CENTREON.Connexion where id = " + connexion.getId()).executeUpdate();
System.out.println(connexion.getId());
tx.commit();
HibernateUtil.sessionClosed() |
parfois la boucle while passe, mais ensuite ca me remet la meme erreur.
aidez-moi svp!