我的问题是这样的:我在两个service中分别调用两个代码几乎相同的dao中方法查询数据库,现在是一个dao正常,另一个在getCurSession(MYSQL).createQuery(sql)句抛出异常,异常:
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
我按照百度的方法,在配置文件中加了这两句话后,
我的配置文件是:
dao:
service:
忘各位帮忙看看,谢谢了
写一个不以这些开头的service方法,比如testService()。看看是不是也是不行。。如果也不行话。就是事物配置的问题。。
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置服务层 -->
<bean id="userDaoAgency" class="com.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="userDao"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<!-- 配置事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<property name="target" ref="userDaoAgency" />
<property name="proxyInterfaces" value="com.dao.UserDao" />
<!-- 配置事务属性 -->
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
http://blog.csdn.net/yinjian520/article/details/8666695
事务方面应该使用Spring来控制吧。
而且你这个是分布式事务么?两个Dao是使用不同数据库么?
图中这两个地方添加: 试试
这两个地方加:
<tx:method name="*" rollback-for="Throwable" propagation="REQUIRED"/>
试试。。刚才怎么代码片段没出来。。
我看到你是两个数据源,查看具体的出问题的数据源的配置、bean和dao的配置。应该是配置出错了。