Spring 2.5 是不是和 Spring2.0 不兼容啊?
原先配置的事务处理现在都不可用了,总是抛出hibernate异常:
javax.servlet.ServletException: org.hibernate.HibernateException: createQuery is not valid without active transaction
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
我的配置如下: hibernate.xml
<?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-2.0.xsd">
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
</beans>
tx.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="load*" read-only="true"/>
<tx:method name="get*" read-only="true"/>
<tx:method name="list*" read-only="true"/>
<tx:method name="*" read-only="false"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:advisor
pointcut="execution(* com.sanlea.shoponline.service.*.*(..))"
advice-ref="transactionAdvice"/>
</aop:config>
</beans>
business.xml
<?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-2.0.xsd">
<!-- DAO -->
<bean id="administratorDao" class="com.sanlea.shoponline.dao.impl.AdministratorDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- Logic -->
<bean id="administratorLogic" class="com.sanlea.shoponline.logic.impl.AdministratorLogicImpl">
<property name="administratorDao" ref="administratorDao" />
</bean>
<!-- Service -->
<bean id="administratorService" class="com.sanlea.shoponline.service.impl.AdministratorServiceImpl">
<property name="administratorDao" ref="administratorDao" />
<property name="administratorLogic" ref="administratorLogic" />
</bean>
</beans>
最近发现spring2.0.1版本对于 ibatis的集成有严重的编码问题的BUG, 如果你的iBatis的xml配置文件是用非当前系统使用的encoding, 在java6下, 会导致xml文件的读取分析错误。 真是个恶心的东西, spring 用一个文件的 Reader接口把XML配置给了Ibatis, 这个肯定是有问题的。
我也碰到过,郁闷
这个问题在下面的链接中有解决方法. http://jira.springframework.org/browse/SPR-4207
本人也遇到了同样的问题(spring 2.5.4 + hibernate3.2.5 ga) 网上搜google 大多数都是说 1,pointcut 配置的问题(已检查)。 2)抛出异常不对(抛出RuntimeException 也没有回滚)
用了Spring当然使用getHibernateTemplate().xxx了。。不会用到什么sessionFactory吧。
无用信息,请忽略
LZ你的方法里面用到:sessionFactory.getCurrentSession();了么?
Hibernate的版本是3.2.5GA
还是没有解决,真奇怪,没有人遇到这样的问题吗?
密切关注中.
看看是不是hibernate版本问题 spring2.5需要3.2以上的hibernate版本
不对,Service类是一些包含业务接口的类,我是拦截它的实例方法,应该没错才对。
在Spring2.0上是可以哦。
spring2.5 内置了annotation的包 不象以前还要加个包
确实有不兼容的地方...transaction, annotation都有问题!
spring2.5对spring2.0是平滑迁移的 一般情况下是不用大动代码!看你的报错应该是事务拦截出错