Spring ORM 4.0.5和Hibernate 4.3.5 -不能保存到数据库



我正在使用Spring ORM 4.0.5和Hibernate 4.3.5,我遇到了困难

当我尝试从tomcat调用dao方法时,我得到以下错误

    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时,它运行得非常好。

这是我的spring配置文件的内容——数据源是单独配置和加载的。

<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>

任何帮助都非常感谢

M. Deinum指出错误

我为我配置了以下内容

<tx:method name="" read-only="false"/>

通过将其更改为以下内容,一切都正常工作

<tx:method name="*" read-only="false"/>

最新更新