`
xiaomogui
  • 浏览: 239427 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

hibernate关于sessions的问题

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

    hibernate_org - Sessions and transactions

    hibernate 教程

    配置,会话和工厂(Configurations, Sessions and Factories) 10.2. 线程和连接(Threads and connections) 10.3. 考虑对象辨别 10.4. 乐观并发控制(Optimistic concurrency control) 10.4.1. 使用...

    J2EE利用Hibernate采用B/S架构网页设计

    * 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 ...

    Hibernate Reference Documentation3.1

    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 ...

    hibernate

    配置,会话和工厂(Configurations, Sessions and Factories) 10.2. 线程和连接(Threads and connections) 10.3. 考虑对象辨别 10.4. 乐观并发控制(Optimistic concurrency control) 10.4.1. 使用...

    hibernate3.6 文档(pdf 格式)

    2.3. Contextual sessions .......................................................................................... 28 3. Configuration ...................................................................

    Learning Spring 5.0

    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的基本...

    java面试宝典

    202、用jdom解析xml文件时如何解决中文问题?如何解析? 48 203、编程用JAVA解析XML的方式. 49 204、EJB2.0有哪些内容?分别用在什么场合? EJB2.0和EJB1.1的区别? 51 205、EJB与JAVA BEAN的区别? 51 206、EJB的基本...

    play框架手册

    关于REST - 14 - routes文件语法 - 14 - HTTP方法 - 15 - URI范示 Pattern - 15 - Java调用定义 - 17 - 把404当作action来用 - 17 - 指派静态参数 - 17 - 变量和脚本 - 18 - 路由优先级 - 18 - 服务器静态资源 - 18 ...

    play framework 框架手册 word 版

    关于REST - 14 - routes文件语法 - 14 - HTTP方法 - 15 - URI范示 Pattern - 15 - Java调用定义 - 17 - 把404当作action来用 - 17 - 指派静态参数 - 17 - 变量和脚本 - 18 - 路由优先级 - 18 - 服务器静态资源 - 18 ...

    The Definitive Guide to NetBeans Platform

    Contents at a Glance Foreword . . . . . . . . ....About the Author ....About the Technical Reviewers ....Acknowledgments....Introduction ....■CHAPTER 1 Introduction ....■CHAPTER 2 Structure of the NetBeans Platform ....

Global site tag (gtag.js) - Google Analytics