论坛首页 入门技术论坛

No Hibernate Session bound to thread 是什么原因

浏览 9999 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-06-11  
2:22:11,640 ERROR [default]: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>
	 


   发表时间:2007-06-11  
没有配置声明性事务,找个入门文章看下吧
0 请登录后投票
   发表时间:2007-06-11  
好了, 但还不知道什么原因。代码也没有改动,莫明的就可以了。感觉是 IE 里的缓存吧。比较郁闷啊
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics