-->
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.  [ 6 posts ] 
Author Message
 Post subject: Help : IllegalStateException
PostPosted: Wed May 31, 2017 7:42 am 
Newbie

Joined: Wed May 31, 2017 7:21 am
Posts: 4
Hello,

Sorry in advance if I'm too long.
Here is my problem.
I deployed a web application (Java 8 / Tomcat 8 / MySQL 5 / Debian 8) several years ago using Hibernate technology and which is unfortunately no longer maintained.
For several weeks, after a few hours or days after the weeks, the application plants and becomes unusable.

The logs show the following error:

Exception levée
Nom IllegalStateException
Message No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
Pile d'exécution java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
Pile d'exécution détaillée java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:349)
org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:199)
org.springframework.orm.hibernate3.HibernateTemplate.getSession(HibernateTemplate.java:422)
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:361)
org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:974)
org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:967)
org.esupportail.helpdesk.dao.HibernateDaoServiceImpl.getVersionManager(HibernateDaoServiceImpl.java:3142)
org.esupportail.helpdesk.dao.HibernateDaoServiceImpl$$FastClassByCGLIB$$a0153163.invoke(<generated>)
net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:696)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:631)
org.esupportail.helpdesk.dao.HibernateDaoServiceImpl$$EnhancerByCGLIB$$9524b5c3.getVersionManager(<generated>)
org.esupportail.helpdesk.domain.DomainServiceImpl.getDatabaseVersion(DomainServiceImpl.java:3933)
org.esupportail.helpdesk.domain.DomainServiceImpl$$FastClassByCGLIB$$21f7d1d.invoke(<generated>)
net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:696)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:631)
org.esupportail.helpdesk.domain.DomainServiceImpl$$EnhancerByCGLIB$$682fcd41.getDatabaseVersion(<generated>)
org.esupportail.helpdesk.services.application.VersionningServiceImpl.checkVersion(VersionningServiceImpl.java:353)
org.esupportail.commons.services.application.VersionningUtils.checkVersion(VersionningUtils.java:99)
org.esupportail.commons.web.servlet.FacesServlet.checkVersion(FacesServlet.java:213)
org.esupportail.commons.web.servlet.FacesServlet.service(FacesServlet.java:356)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1580)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1537)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)


Knowing that I can not modify the Java code, I try to modify my connection pool or XML DAO files in order to remedy this problem but unfortunately without success.

Here is my pool declared in the server.xml of my Tomcat :

Code:
                <Resource name="jdbc/esup-helpdesk"
                    type="javax.sql.DataSource"
                    username="*********"
                    password="**************"
                    driverClassName="com.mysql.jdbc.Driver"
                    url="jdbc:mysql://**********/********?autoReconnect=true"
                    maxActive="100"
                    maxIdle="10"
                    maxWait="10000"
                    poolPreparedStatements="true"
                    removeAbandoned="true"
                    removeAbandonedTimeout="60"
                    logAbandoned="true"
                    validationQuery="select '1'"
                    validationInterval="30000"
                    timeBetweenEvictionRunsMillis="30000"
                    abandonWhenPercentageFull="50"
                    jdbcInterceptors="ResetAbandonedTimer"/>


As well as the hibernate DAO file :

Code:
<?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>
        <!--
                /properties/dao/hibernate/hibernate.cfg.xml
                The main Hibernate configuration file.
                It is referenced from /properties/dao/dao.xml
                and the database mapping is in folder
                /properties/dao/hibernate/mapping.
        -->
        <session-factory>
                <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
                <property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
                <property name="hibernate.connection.datasource">java:/comp/env/jdbc/esup-helpdesk</property>
                <property name="hibernate.connection.autocommit">false</property>
                <property name="hibernate.connection.charSet">UTF-8</property>
                <property name="hibernate.show_sql">false</property>
                <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
                <property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
                <property name="connection.autoReconnectForPools">true</property>
                <property name="connection.is-connection-validation-required">true</property>
                <property name="connection.autoReconnect">true</property>
                <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
                <property name="hibernate.jdbc.fetch_size">25</property>
                <property name="hibernate.jdbc.batch_size">25</property>
                <property name="hibernate.jdbc.use_scrollable_resultset">true</property>
                <property name="hibernate.jdbc.use_streams_for_binary">true</property>
                <property name="hibernate.max_fetch_depth">1</property>
                <property name="hibernate.cache.use_query_cache">false</property>
                <property name="hibernate.cache.use_second_level_cache">false</property>
                <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
                <property name="hibernate.current_session_context_class">thread</property>
                <property name="exposeTransactionAwareSessionFactory">false</property>
        <property name="dbcp.validationQuery">select 1</property>
        <property name="dbcp.testOnReturn">true</property>
        <property name="dbcp.testWhileIdle">true</property>
        <property name="dbcp.timeBetweenEvictionRunsMillis">10000</property>
        <property name="dbcp.numTestsPerEvictionRun">10</property>
        </session-factory>
</hibernate-configuration>


Not at all comfortable with Hibernate, do you have parameters to advise me / modify (see https://docs.jboss.org/hibernate/orm/3. ... ation.html) which I can add to my DAO file to remedy the error: "java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here "

Thanks in advance.

Cordially.

PS: the lib hibernate used are the following versions hibernate-3.3.1.ga.jar and spring-hibernate3-2.0.8.jar


Last edited by devfabien on Thu Jun 01, 2017 4:55 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Help : IllegalStateException
PostPosted: Wed May 31, 2017 10:03 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Since you're using Spring, you should provide the DataSource via Spring, not Hibernate.

So, delete the following lines from your hibernate.cfg.xml:

Code:
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.datasource">java:/comp/env/jdbc/esup-helpdesk</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
<property name="connection.autoReconnect">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="exposeTransactionAwareSessionFactory">false</property>
<property name="dbcp.validationQuery">select 1</property>
<property name="dbcp.testOnReturn">true</property>
<property name="dbcp.testWhileIdle">true</property>
<property name="dbcp.timeBetweenEvictionRunsMillis">10000</property>
<property name="dbcp.numTestsPerEvictionRun">10</property>


You don't need those. Spring should provide the DataSource and the Transaction management logic for you. For more info about how to setup Spring, check their documentation.


Top
 Profile  
 
 Post subject: Re: Help : IllegalStateException
PostPosted: Wed May 31, 2017 11:05 am 
Newbie

Joined: Wed May 31, 2017 7:21 am
Posts: 4
Thanks for answer but if i delete all this lines in hibernate.cfg.xml, how the application could find the datasource (jdbc/esup-helpdesk) define in my server.xml ?

For information, i have only this documentation for datasource : https://www.esup-portail.org/wiki/displ ... connection (i use JNDI)

Thanks for answer.


Top
 Profile  
 
 Post subject: Re: Help : IllegalStateException
PostPosted: Wed May 31, 2017 12:24 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Check out this tutorial to see how you should set Spring, Hibernate and JNDI.


Top
 Profile  
 
 Post subject: Re: Help : IllegalStateException
PostPosted: Thu Jun 01, 2017 3:43 am 
Newbie

Joined: Wed May 31, 2017 7:21 am
Posts: 4
vlad wrote:
Check out this tutorial to see how you should set Spring, Hibernate and JNDI.


Thanks for your reply but my goal is not to change the operation of the application by forcing it to go through Spring.
Especially since I will have too many modifications to bring to the Java classes of the application if I am your tutorial ...
As a reminder, currently the application works this way and the hibernate.cfg.xml file is actually used.

I just need to know if there is an attribute that I can add to my file hibernate.cfg.xml (see https://docs.jboss.org/hibernate/orm/3. ... n-optional) to limit the error "java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"

Thanks a lot for your answer


Top
 Profile  
 
 Post subject: Re: Help : IllegalStateException
PostPosted: Thu Jun 01, 2017 4:29 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
This exception is thrown because of the way Hibernate Sessions are bound to current running threads. There is no configuration to magically fix your issue, you have to debug it through this time.


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

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.