`
juggler
  • 浏览: 166272 次
  • 性别: Icon_minigender_1
  • 来自: 广东
社区版块
存档分类
最新评论

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>
分享到:
评论
14 楼 sdh5724 2008-10-26  
最近发现spring2.0.1版本对于 ibatis的集成有严重的编码问题的BUG, 如果你的iBatis的xml配置文件是用非当前系统使用的encoding, 在java6下, 会导致xml文件的读取分析错误。 真是个恶心的东西, spring 用一个文件的 Reader接口把XML配置给了Ibatis, 这个肯定是有问题的。
13 楼 saturn 2008-10-25  
rock_li 写道

本人也遇到了同样的问题(spring 2.5.4 + hibernate3.2.5 ga)
网上搜google 大多数都是说 1,pointcut 配置的问题(已检查)。
2)抛出异常不对(抛出RuntimeException 也没有回滚)


我也碰到过,郁闷

12 楼 piggy 2008-10-17  
这个问题在下面的链接中有解决方法.
http://jira.springframework.org/browse/SPR-4207
11 楼 rock_li 2008-06-30  

本人也遇到了同样的问题(spring 2.5.4 + hibernate3.2.5 ga)
网上搜google 大多数都是说 1,pointcut 配置的问题(已检查)。
2)抛出异常不对(抛出RuntimeException 也没有回滚)
10 楼 EXvision 2008-02-28  
marsoon 写道
LZ你的方法里面用到:sessionFactory.getCurrentSession();了么?


用了Spring当然使用getHibernateTemplate().xxx了。。不会用到什么sessionFactory吧。
9 楼 movingboy 2008-02-27  
无用信息,请忽略
8 楼 marsoon 2008-02-27  
LZ你的方法里面用到:sessionFactory.getCurrentSession();了么?
7 楼 juggler 2007-12-13  
Hibernate的版本是3.2.5GA

还是没有解决,真奇怪,没有人遇到这样的问题吗?
6 楼 hbrf2007 2007-12-13  
密切关注中.
5 楼 andyao 2007-12-12  
看看是不是hibernate版本问题
spring2.5需要3.2以上的hibernate版本
4 楼 juggler 2007-12-11  
antonyup_2006 写道
spring2.5对spring2.0是平滑迁移的  一般情况下是不用大动代码!看你的报错应该是事务拦截出错


不对,Service类是一些包含业务接口的类,我是拦截它的实例方法,应该没错才对。

在Spring2.0上是可以哦。
3 楼 antonyup_2006 2007-12-11  
spring2.5 内置了annotation的包 不象以前还要加个包
2 楼 lordhong 2007-12-10  
确实有不兼容的地方...transaction, annotation都有问题!
1 楼 antonyup_2006 2007-12-10  
spring2.5对spring2.0是平滑迁移的  一般情况下是不用大动代码!看你的报错应该是事务拦截出错

相关推荐

Global site tag (gtag.js) - Google Analytics