Hi all,
my problem is a
java.lang.IllegalStateException: No Hibernate Session bound to thread...
Code:
...
2008-11-23 00:40:30,612 [main] INFO org.hibernate.transaction.TransactionFactoryFactory - Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
2008-11-23 00:40:30,612 [main] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
...
2008-11-23 00:40:30,690 [main] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
2008-11-23 00:40:31,018 [main] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
2008-11-23 00:40:31,049 [main] INFO org.springframework.orm.hibernate3.HibernateTransactionManager - Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@19977bd] of Hibernate SessionFactory for HibernateTransactionManager
...
java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:352)
at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:202)
at com.project.service.data.GeoIpHibernateDAO.locate(GeoIpHibernateDAO.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
at $Proxy17.locate(Unknown Source)
at com.project.service.servlet.LocaterServlet.doPost(LocaterServlet.java:40)
at com.project.service.servlet.LocaterServlet.doGet(LocaterServlet.java:29)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
I use Hibernate 3 in combination with Spring to provide services that will be called from a Adobe Flex frontend above BlazeDS as RemoteObjects.
Code:
...
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="annotatedClasses">
<list>
<value>com.project.service.data.Country</value>
<value>com.project.service.data.Language</value>
<value>com.project.service.data.User</value>
<value>com.project.service.data.Location</value>
<value>com.project.service.data.GeoIp</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
...
<!-- geo ip service -->
<bean id="geoIpDAOBeanTarget" class="com.project.service.data.GeoIpHibernateDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="geoIpDAOBean" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="txManager" />
<property name="target" ref="geoIpDAOBeanTarget" />
<property name="transactionAttributes">
<props>
<prop key="locateIp">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
...
The configuration works very well, but now I need an additional regular Servlet and I thought that I could share the DAOs. To access the needed DAO I use the WebApplicationContext of Spring as a BeanFactory.
Code:
...
try {
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
GeoIpDAO geoIpDAO = (GeoIpDAO)context.getBean("geoIpDAOBean");
geoIp = geoIpDAO.locate(ip);
} catch(Exception e) {
e.printStackTrace();
}
...
I can access the DAO, but the mySQL query will result in the java.lang.IllegalStateException. My opinion is that a Session is given to the DAO by my xml config in applicationContext.xml.
Do I need another Session for my Servlet?
Does anybody have an idea to solve this issue?
Please help me :-|.
Thx a lot,
Nepumuk