当前位置: 代码迷 >> J2EE >> No Hibernate Session bound to thread, and configuration does not allow creation,该如何解决
  详细解决方案

No Hibernate Session bound to thread, and configuration does not allow creation,该如何解决

热度:83   发布时间:2016-04-17 23:35:15.0
No Hibernate Session bound to thread, and configuration does not allow creation
异常如下:
Exception in thread "Thread-4" 
org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622)
at com.mingmob.util.hibernate.SimpleHibernateDao.getSession(SimpleHibernateDao.java:85)
at com.mingmob.util.hibernate.SimpleHibernateDao.save(SimpleHibernateDao.java:93)


spring配置如下:

<!-- 事务管理器 -->  
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
        <property name="sessionFactory" ref="sessionFactory"></property>  
    </bean>  
    <!-- 使用annotation定义事务 -->  
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />  
    <!-- 事务代理类 -->  
    <bean id="transactionBese" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"  
        lazy-init="true" abstract="true">  
        <property name="transactionManager" ref="transactionManager"></property>  
        <property name="transactionAttributes">  
            <props>  
                <prop key="add*">PROPAGATION_REQUIRED,-Exception</prop>  
                <prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>  
                <prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="handle*">PROPAGATION_REQUIRED,-Exception</prop>
                <prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>  
                <prop key="modify*">PROPAGATION_REQUIRED,-Exception</prop>  
                <prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>  
                <prop key="del*">PROPAGATION_REQUIRED,-Exception</prop>  
                <prop key="get*">PROPAGATION_NEVER</prop>  
            </props>  
        </property>  
    </bean>


Session是这么获取的:

public Session getSession() {
return sessionFactory.getCurrentSession();
}


hibernate3+spring3,各种贴说是没有配置事务支持,我在service上已经添加了@Transactional。
问题还是没有解决。
程序有用到线程。





求解!!!!
在线等哦~~~~~

~ -_- ~
------解决思路----------------------
必须是没配置好事务
楼主仔细检查下
你贴的这些信息看不出问题
------解决思路----------------------
既然用了注解配置事务,为什么还要用proxy-target-class="true"呢,我感觉,从proxy-target-class="true"之后一直到事务代理bean结束,都不用写
  相关解决方案