这个弹簧配置怎么会不起作用? [英] How could this spring configuration not working?
问题描述
我得到:getNamedQuery在没有活动事务的情况下是无效的: org.hibernate.HibernateException:没有活动的交易,getNamedQuery无效
I got: getNamedQuery is not valid without active transaction: org.hibernate.HibernateException: getNamedQuery is not valid without active transaction
org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:340)
$Proxy10.getNamedQuery(Unknown Source)
这是我的配置
...
<context:annotation-driven/>
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
...
我还添加了context:annotation-driven,因为tr:annotation-driven无法正常工作,<tx:annotation-driven/>
是否使用transactionManager
从休眠中获取其自己的会话?
Also, I added context:annotation-driven since the tr:annotation-driven is not working, does <tx:annotation-driven/>
use the transactionManager
which obtain its own session from hibernate?
我在带注释的事务中使用了hibernate3派生的sessionFactory
,那么如何配置spring呢?
I used my derived sessionFactory
using hibernate3 inside the annotated transaction, so how do I configure the spring to do so?
推荐答案
事务管理器对用于管理事务的会话工厂具有依赖性.
The transaction manager has a dependency on session factory which it's using to manage transactions.
通过添加<tx:annotation-driven />
,您可以告诉Spring如何划分事务.在这种情况下,您可以使用注释.
By adding <tx:annotation-driven />
you tell Spring how transactions are demarcated. In this case you can use annotations.
See the docs page how to use XML Schema-based configuration:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- bean definitions here -->
</beans>
这篇关于这个弹簧配置怎么会不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!