javax.servlet.ServletException: org.hibernate.HibernateException:
Illegal attempt to associate a collection with two open sessions
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
当我第一次从页面向数据库插入数据的时候,插入正常!!当我返回上一级页面的时候就出现了上面的错误!我hibernate使用spring管理的!在网上看到说是如果hibernate用spring管理的话,session就不用我们关闭了。。spring会自动的帮我们关闭!!我没有加session.close();
就出现了上面的错误!我加了session.close()方法后。就没有出现上面的错误!!
为什么啊??还在研究中!!!!!!!!
代码:
public void insert(User user) {
//向数据库中插入一个用户:
Session session = getSession();
session.save(user);
session.close();
}
分享到:
相关推荐
hibernate_org - Sessions and transactions
配置,会话和工厂(Configurations, Sessions and Factories) 10.2. 线程和连接(Threads and connections) 10.3. 考虑对象辨别 10.4. 乐观并发控制(Optimistic concurrency control) 10.4.1. 使用...
* Configures and provides access to Hibernate sessions, tied to the * current thread of execution. Follows the Thread Local Session * pattern, see {@link http://hibernate.org/42.html }. */ public ...
2.5. Contextual Sessions 3. Configuration 3.1. Programmatic configuration 3.2. Obtaining a SessionFactory 3.3. JDBC connections 3.4. Optional configuration properties 3.4.1. SQL Dialects 3.4.2. Outer ...
配置,会话和工厂(Configurations, Sessions and Factories) 10.2. 线程和连接(Threads and connections) 10.3. 考虑对象辨别 10.4. 乐观并发控制(Optimistic concurrency control) 10.4.1. 使用...
2.3. Contextual sessions .......................................................................................... 28 3. Configuration ...................................................................
Implement and integrate a persistent layer in your application and also integrate an ORM such as Hibernate Understand how to manage cross-cutting with logging mechanism, transaction management, and ...
202、用jdom解析xml文件时如何解决中文问题?如何解析? 48 203、编程用JAVA解析XML的方式. 49 204、EJB2.0有哪些内容?分别用在什么场合? EJB2.0和EJB1.1的区别? 51 205、EJB与JAVA BEAN的区别? 51 206、EJB的基本...
202、用jdom解析xml文件时如何解决中文问题?如何解析? 48 203、编程用JAVA解析XML的方式. 49 204、EJB2.0有哪些内容?分别用在什么场合? EJB2.0和EJB1.1的区别? 51 205、EJB与JAVA BEAN的区别? 51 206、EJB的基本...
关于REST - 14 - routes文件语法 - 14 - HTTP方法 - 15 - URI范示 Pattern - 15 - Java调用定义 - 17 - 把404当作action来用 - 17 - 指派静态参数 - 17 - 变量和脚本 - 18 - 路由优先级 - 18 - 服务器静态资源 - 18 ...
关于REST - 14 - routes文件语法 - 14 - HTTP方法 - 15 - URI范示 Pattern - 15 - Java调用定义 - 17 - 把404当作action来用 - 17 - 指派静态参数 - 17 - 变量和脚本 - 18 - 路由优先级 - 18 - 服务器静态资源 - 18 ...
Contents at a Glance Foreword . . . . . . . . ....About the Author ....About the Technical Reviewers ....Acknowledgments....Introduction ....■CHAPTER 1 Introduction ....■CHAPTER 2 Structure of the NetBeans Platform ....