`

No Hibernate Session bound to thread 是什么原因

阅读更多
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>
	 


分享到:
评论
2 楼 pxysea 2007-06-11  
好了, 但还不知道什么原因。代码也没有改动,莫明的就可以了。感觉是 IE 里的缓存吧。比较郁闷啊
1 楼 dennis_zane 2007-06-11  
没有配置声明性事务,找个入门文章看下吧

相关推荐

    org.hibernate.HibernateException: No Hibernate Session bound to thread

    然而,在使用 Hibernate 进行数据库操作时,经常会遇到 "No Hibernate Session bound to thread" 的错误信息。本文将详细介绍该错误的解决方案。 错误原因 "No Hibernate Session bound to thread" 错误信息通常是...

    Hibernate-nosession

    首先,理解什么是Hibernate Session。Session是Hibernate中的核心接口,它充当了应用程序和数据库之间的桥梁,负责对象的持久化操作,如保存、更新、删除和查询等。Session通常在一个事务中打开并在事务结束时关闭,...

    OA系统整体设计及约定、搭建环境.rar_OA系统及配置_OA系统整体设计及约定、搭建环境_creation

    hibernate就会抛出: No Hibernate Session bound to thread, and configuration does not allow creation of one here}异常。 在实际的SSH web应用开发中,我们通常用spring来进行事务的管理。我们一般不会在dao层...

    JAVA错误文档.pdf

    4. Hibernate框架错误:文档还包含了“org.hibernate.HibernateException: No Hibernate Session bound to thread”等错误信息,这是Hibernate框架常见的异常,表明在当前线程上没有绑定Hibernate Session。...

    使用Hibernate一些常见错误解决办法

    当遇到`no current session bound to current context`错误时,通常是因为事务管理方式不正确。Hibernate提供了多种会话上下文配置,如`thread`、`jta`等。在这种情况下,推荐使用`thread`配置,确保每个线程都有...

Global site tag (gtag.js) - Google Analytics