From a search of this forum this is a rather popular error :)
The error I'm getting is:
No Hibernate Session bound to thread, and configuration does not allow creating of non-transactional one here
I'm using Hibernate 1.2.4.
Basically I get this error in a JUnit test when I'm actually going against a real (Sybase) database.
If I run the unit test against an in memory database (hsqldb), I don't get this error - all is good.
When the actual code is run in production (inside JBoss) against a real database (Sybase), there is no problem.
The only time I see this is with a JUnit test running against a real Sybase database.
The error in the JUnit test case occurs at the line.
Code:
Session session = getHibernateTemplate().getSessionFactory().getCurrentSession();
Here's my configuration:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="sybaseHibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SybaseDialect</prop>
<prop key="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</prop>
<prop key="hibernate.connection.url">jdbc:jtds:sybase://somedomain.com:5000/SomeDBName</prop>
<prop key="hibernate.connection.username">user</prop>
<prop key="hibernate.connection.password">password</prop>
<prop key="hibernate.connection.pool_size">1</prop>
<prop key="hibernate.connection.autocommit">false</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
<prop key="hibernate.jdbc.fetch_size">512</prop>
<prop key="hibernate.jdbc.batch_size">30</prop>
<prop key="hibernate.hbm2ddl.auto">none</prop>
</props>
</property>
</bean>
<bean id="mappingResourcesList" class="org.springframework.beans.factory.config.ListFactoryBean">
<property name="sourceList">
<list>
<value>com/somedomain/hibernate/DoSomething.hbm.xml</value>
</list>
</property>
</bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" lazy-init="false">
<property name="mappingResources">
<ref bean="mappingResourcesList"/>
</property>
<property name="hibernateProperties">
<ref bean="sybaseHibernateProperties"/>
</property>
</bean>
<bean id="myHibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate" lazy-init="true">
<property name="sessionFactory" ref="mySessionFactory"/>
</bean>
<bean id="myDAOImpl" class="com.somedomain.MyDAO" lazy-init="true">
<property name="hibernateTemplate" ref="myHibernateTemplate"/>
</bean>
<bean id="myTransactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" lazy-init="true">
<property name="sessionFactory" ref="mySessionFactory" />
</bean>
<bean id="myDAO" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" lazy-init="true">
<property name="transactionManager" ref="myTransactionManager"/>
<property name="target" ref="myDAOImpl"/>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
So what am I doing wrong ?
I'm a hibernate newbie BTW in case you haven't figured it out.