开发者

HibernateSystemException: No Hibernate Session bound to thread

I am getting HibernateSystemException although I did everything that is mentioned on different forums.

Here is a part of applicationContext.xml

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property nam开发者_开发技巧e="dataSource" ref="dataSource"/>
</bean>

I also placed @Transactional annotaion above my class.

@Transactional
public class MyClassImpl


A) this is the wrong transaction manager:

<bean id="transactionManager" 
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource"/>
</bean>

you need org.springframework.orm.hibernate3.HibernateTransactionManager, as you can see in 13.3.3 Hibernate > Declarative transaction demarcation.

DataSourceTransactionManager is for plain JDBC, not for Hibernate (see 12.3.8 JDBC > DataSourceTransactionManager).

B) you need this line also:

<tx:annotation-driven transaction-manager="transactionManager" />


Have you checked that this markup is present in you application context file ?

<context:annotation-config />

It is necessary to consider your annotations.


Did you include the tx namespace in your configuration?

HibernateSystemException: No Hibernate Session bound to thread


Before doing any request, you could try this piece of code :

Session session = SessionFactoryUtils.getSession(dataSource, null, null);
TransactionSynchronizationManager.bindResource(dataSource, new SessionHolder(session));

Please keep me informed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜