hibernate错误提示: No Hibernate Session bound to thread, and configuration does not allow creation of no

来源:互联网 发布:nba2k16mc最帅捏脸数据 编辑:程序博客网 时间:2024/05/19 17:26

org.hibernate.HibernateException: No Hibernate Session bound to thread, andconfiguration does not allow creation of non-transactional one here

    atorg.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)

    atorg.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622)

    at com.dao.impl.MyTypeImpl.getParent(MyTypeImpl.java:29)



一直也找不到原因,后来突然发现,自己确实是没有配置事物,自己的那个操作方法名字是:

public List<MyType> getParent();

而事务配置为

     <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory"></property></bean><tx:annotation-driven transaction-manager="transactionManager" /><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="Add*" propagation="REQUIRED" isolation="DEFAULT" /><tx:method name="Delete*" propagation="REQUIRED" isolation="DEFAULT" /><tx:method name="Update*" propagation="REQUIRED" isolation="DEFAULT" /><tx:method name="Query*" propagation="NOT_SUPPORTED" isolation="DEFAULT" /><tx:method name="LoginInfo*" propagation="NOT_SUPPORTED" isolation="DEFAULT" /><tx:method name="QueryAll*" propagation="NOT_SUPPORTED" isolation="DEFAULT" /></tx:attributes></tx:advice>

事务里没有配置以“get”开头的方法名,所以导致使用get开发方法错误,加上<tx:method name="get*" propagation="NOT_SUPPORTED" isolation="DEFAULT" />后问题解决,修改后的配置文件如下:


<tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><tx:method name="Add*" propagation="REQUIRED" isolation="DEFAULT" /><tx:method name="Delete*" propagation="REQUIRED" isolation="DEFAULT" /><tx:method name="Update*" propagation="REQUIRED" isolation="DEFAULT" /><tx:method name="Query*" propagation="NOT_SUPPORTED" isolation="DEFAULT" /><tx:method name="LoginInfo*" propagation="NOT_SUPPORTED" isolation="DEFAULT" /><tx:method name="QueryAll*" propagation="NOT_SUPPORTED" isolation="DEFAULT" /><tx:method name="get*" propagation="NOT_SUPPORTED" isolation="DEFAULT" /></tx:attributes></tx:advice>



原创粉丝点击