Spring ORM 4.0.5和Hibernate 4.3.5 - 无法保存到数据库 [英] Spring ORM 4.0.5 and Hibernate 4.3.5 - Cant save to database
问题描述
我正在使用Spring ORM 4.0.5和Hibernate 4.3.5,并且遇到困难
I am using Spring ORM 4.0.5 and Hibernate 4.3.5 and I am running into difficulties
当我尝试从tomcat调用dao方法时,以下错误:
When I try to call a dao method from tomcat, I get the following error
20140527 12:25:00,031 IST DEBUG hibernate4.HibernateTemplate [Check App Scheduler_Worker-1] Could not retrieve pre-bound Hibernate session
org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:106)
at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014)
at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:325)
我从我的动作通过服务层调用我的dao方法。
当我使用相同的spring xml文件从junit对dao进行测试时,它工作得非常好。
I am calling my dao methods through a service layer from my actions. When I run test to the dao from junit using the same spring xml file, it works perfectly well.
这里是我的spring配置文件的内容 - - 数据源被单独配置和加载。
Here are the contents of my spring configuration file -- datasources are configured and loaded separately.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Hibernate session factory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="appDataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>config/hibernateMappings/User.hbm.xml</value>
</list>
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- the transactional semantics... -->
<tx:attributes>
<!-- all methods starting with get are read-only -->
<tx:method name="get*" read-only="true"/>
<!-- other methods use the default transaction settings (see below) -->
<tx:method name="" read-only="false"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="servicesOperation" expression="execution(* com.app.services.user..*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="servicesOperation"/>
</aop:config>
赞赏
Any help on this is greatly appreciated
推荐答案
M. Deinum指出错误
Error was pointed out by M. Deinum
I为我配置了
I had the following configured for me
<tx:method name="" read-only="false"/>
通过将其更改为以下内容,一切正常工作
By changing it to the following, everything worked correctly
<tx:method name="*" read-only="false"/>
这篇关于Spring ORM 4.0.5和Hibernate 4.3.5 - 无法保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!