作者:汽车之家马甲小宝宝_457 | 来源:互联网 | 2023-05-17 12:13
Exceptioninthreadmainorg.hibernate.HibernateException:NoHibernateSessionboundtothread,a
Exception in thread "main" 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.wz.dao.basic.BasicDao.executeQuery(BasicDao.java:34)
at com.wz.test.Test.main(Test.java:22)
applicationContext.xml 文件配置
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
value="classpath:hibernate.cfg.xml">
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
6 个解决方案
你的Dao要使用spring的话hibernateTemplet