pxysea 发表于 2013-2-3 14:29:04

No Hibernate Session bound to thread 是什么原因

2:22:11,640 ERROR :250 - Servlet.service() for servlet default threw exception
java.lang.IllegalStateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SessionFactoryUtils.doGetSession(SessionFactoryUtils.java:350)
at org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(SessionFactoryUtils.java:200)
at com.sea.user.dao.BaseDAO.getSession(BaseDAO.java:23)
at com.sea.user.dao.impl.UserDAO.saveUser(UserDAO.java:16)
at com.sea.user.service.impl.UserService.saveUser(UserService.java:14)
at com.sea.user.action.UserAction.register(UserAction.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)


请解决一下,谢谢!

这是BaseDAO内容
public class BaseDAO {private SessionFactory sessionFactory;public SessionFactory getSessionFactory() {return sessionFactory;}public void setSessionFactory(SessionFactory sessionFactory) {this.sessionFactory = sessionFactory;}public Session getSession(){Session session = sessionFactory.openSession();return session;}}
applicationContext.xml 文件配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"><bean id="dataSource"class="org.apache.commons.dbcp.BasicDataSource"><property name="driverClassName"value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/cms"></property><property name="username" value="root"></property><property name="password" value="root"></property></bean> <bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><property name="dataSource"><ref bean="dataSource" /></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.show_sql">false</prop></props></property><property name="mappingResources"><list><value>com/sea/user/vo/Users.hbm.xml</value><value>com/sea/user/vo/Usersdetail.hbm.xml</value></list></property></bean> <bean id="baseDAO" class="com.sea.user.dao.BaseDAO"><property name="sessionFactory"><ref bean="sessionFactory"/></property></bean><bean id="userDAO" class="com.sea.user.dao.impl.UserDAO" parent="baseDAO" ></bean><bean id="userService" class="com.sea.user.service.impl.UserService"><property name="userDAO"><ref bean="userDAO"/></property></bean><bean id="userAction" class="com.sea.user.action.UserAction"><property name="userService"><ref bean="userService"/></property></bean></beans>
页: [1]
查看完整版本: No Hibernate Session bound to thread 是什么原因