- 浏览: 141372 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (88)
- struts (8)
- js (8)
- hibernate (11)
- spring (1)
- j2ee (1)
- ajax (1)
- oracle (21)
- mysql (4)
- tomcat (1)
- php (0)
- java设计模式 (0)
- jms (0)
- 感言 (1)
- linux (0)
- 算法 (1)
- velocity (2)
- python (0)
- prototype (2)
- axis (0)
- Test (4)
- java (5)
- 模板 (1)
- 服务器 (0)
- 移动互联网 (0)
- hadoop (0)
- impala (0)
- hive (0)
- hdfs (0)
- mongodb (0)
- storm (0)
- spark (0)
- flume (0)
- kafka (0)
- 管理知识 (9)
最新评论
-
cwftalus:
insert into 无法实现
Infobright入库 -
红级主:
问题是我就不知道sys的密码,进入其他的用户也改不了密码吧?
ORACLE 中更改用户密码的方法
1.could not load an entity (get)
2.23:31:32,468 ERROR LazyInitializationException:19 - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed (load)
Lazy问题可以通过加opensessioninviewfilter解决
在web.xml中加上
<filter>
<filter-name>openSessionInViewFilter </filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter </filter-name>
<url-pattern>*.do </url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>openSessionInViewFilter </filter-name>
<url-pattern>*.jsp </url-pattern>
</filter-mapping>
经过调试是 LAZY的问题.
我的解决办法是:
<many-to-one>里面的属性lazy="false"
<set>里面的属性lazy="true"
<one-to-many>
</set>
有不对的地方,请大家补充
其次关于load取数据出现问题是因为取数据的表有级联关系,在我们分析此问题之前,我们先要明白hibernate中什么是load,什么是get,它们两者之间有什么区别呢??
只要你在以往的开发过程中稍加注意,不难发现,假如有两张表,他们为一对多关系,现在开始查询,如果使用get,那么查询的结果将会是把2张表的数据全部持久化到内存中(如果关系比较深你还打算用它吗?),如果是采用load的方式,那么将只会是把其中一张表(A表)的数据加载到内存中,而另一张表(B表)只存在一个标识,原则上是等页面显示时,如果只要显示A表数据,那么程序直接内存中找A表数据,如果还要显示B表数据,那么就要通过内存中B表的标识重新查找数据库,此时,问题出来了,假如你在DAO中,session.load之后你结束了session的生命周期,那么在页面要显示B表数据,而B表在内存中只是一个标识啊,你的session又处于关闭状态,它无法找啊,这就会出现上面你遇到的那个问题,因此,假如我们不关闭session,页面可以正常显示2张表的数据了,但是问题又来了,如果不关闭session,那么对象将一直以持久态的形式保存在内存中,留下的隐患难以想象(比如该对象容易数据混乱等等),千万不要说session.clear之内的东西也可以把对象变游离态之内的话啊,如果你彻底用session.clear取代session.close的话,嘿嘿,自己去尝试吧,当问题显现出来的时候痛苦吧^_^!好了,我还是说下解决方法吧~最好的方法就是将DAO中的session与事物全部抽取出来做成一个hibernate过滤器,这样既能解决你上面的问题,又能大大减少DAO中的代码...好处很多的哦,使用一次之后就容易上瘾
2.23:31:32,468 ERROR LazyInitializationException:19 - could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed (load)
Lazy问题可以通过加opensessioninviewfilter解决
在web.xml中加上
<filter>
<filter-name>openSessionInViewFilter </filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>openSessionInViewFilter </filter-name>
<url-pattern>*.do </url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>openSessionInViewFilter </filter-name>
<url-pattern>*.jsp </url-pattern>
</filter-mapping>
经过调试是 LAZY的问题.
我的解决办法是:
<many-to-one>里面的属性lazy="false"
<set>里面的属性lazy="true"
<one-to-many>
</set>
有不对的地方,请大家补充
其次关于load取数据出现问题是因为取数据的表有级联关系,在我们分析此问题之前,我们先要明白hibernate中什么是load,什么是get,它们两者之间有什么区别呢??
只要你在以往的开发过程中稍加注意,不难发现,假如有两张表,他们为一对多关系,现在开始查询,如果使用get,那么查询的结果将会是把2张表的数据全部持久化到内存中(如果关系比较深你还打算用它吗?),如果是采用load的方式,那么将只会是把其中一张表(A表)的数据加载到内存中,而另一张表(B表)只存在一个标识,原则上是等页面显示时,如果只要显示A表数据,那么程序直接内存中找A表数据,如果还要显示B表数据,那么就要通过内存中B表的标识重新查找数据库,此时,问题出来了,假如你在DAO中,session.load之后你结束了session的生命周期,那么在页面要显示B表数据,而B表在内存中只是一个标识啊,你的session又处于关闭状态,它无法找啊,这就会出现上面你遇到的那个问题,因此,假如我们不关闭session,页面可以正常显示2张表的数据了,但是问题又来了,如果不关闭session,那么对象将一直以持久态的形式保存在内存中,留下的隐患难以想象(比如该对象容易数据混乱等等),千万不要说session.clear之内的东西也可以把对象变游离态之内的话啊,如果你彻底用session.clear取代session.close的话,嘿嘿,自己去尝试吧,当问题显现出来的时候痛苦吧^_^!好了,我还是说下解决方法吧~最好的方法就是将DAO中的session与事物全部抽取出来做成一个hibernate过滤器,这样既能解决你上面的问题,又能大大减少DAO中的代码...好处很多的哦,使用一次之后就容易上瘾
发表评论
-
hibernate建表
2009-08-06 21:19 2296Hibernate配置文件: <hibernate-c ... -
hibernate 分页
2009-05-03 14:33 0http://www.iteye.com/topic/7636 ... -
8.4生成配置文件hibernate.cfg.xml
2009-05-02 16:08 0http://book.51cto.com/art/20080 ... -
hibernate 生成sql
2009-05-02 15:56 0[url]http://www.wikihow.com/Gen ... -
37.8 Hibernate的自动生成工具
2009-05-02 15:14 0http://book.csdn.net/bookfiles/ ... -
Hibernate注释下的自定义架构实现
2009-05-02 15:07 0Hibernate注释下的自定义架构实现 http://www ... -
hibernate 分页
2009-04-25 20:27 864三个参数, 第一个是HQL语句,如from EntryObj ... -
Could not load org.apache.xerces.util.EncodingMa
2009-04-20 22:22 2958出现此错误的原因是在hibernate 映射文件中引入了不存在 ... -
org.springframework.orm.hibernate3.HibernateSystem
2009-04-07 21:04 1923出现此错误的愿意是主表,附表 的关联字段问题,附表中的外键与主 ... -
org.hibernate.tuple.PojoEntityTuplizer.setProperty
2009-04-03 18:12 1210err.org.hibernate.tuple.PojoEnt ... -
using operator "."
2009-03-30 09:38 0javax.servlet.jsp.el.ELExceptio ... -
在Hibernate中使用oracle的sequence产生主键
2009-03-29 11:24 0在Hibernate中使用oracle的sequence产生主 ... -
hibernate延迟
2009-03-24 09:16 0lazy="false"的解释 Hibe ... -
Hibernate深入研究3-1
2009-03-23 20:19 0[url] http://www.blogjava.net/a ... -
浅谈对象在Hibernate中的状态
2009-03-23 19:35 805浅谈对象在Hibernate中的 ... -
第 14 章 HQL: Hibernate查询语言
2009-03-15 22:01 0http://www.redsaga.com/hibernat ... -
Hibernate 复合查询
2009-03-15 21:45 0复合查询主要是处理,具有关联关系的两个实体怎样进行关联查询,比 ... -
could not initialize proxy - Session was closed
2009-03-10 11:01 850转自 http://hi.baidu.com/k_boy/bl ... -
could not initialize proxy
2009-03-10 10:58 1236could not initialize proxy - th ... -
hibernate 异常处理
2009-03-05 16:14 1289异常:not-null property references ...
相关推荐
H2 1.4 "Lob not found" 问题 - 在 1.4.183 中修复!...org.hibernate.exception.GenericJDBCException: could not load an entity: [de.bwaldvogel.LobEntity#1] at org.hibernate.exception.SQLStateConverter.handl
Caused By: org.apache.ibatis.builder.BuilderException: Could not find SQL statement to include with refid 'SAD02.SAD02_COL' at org.apache.ibatis.builder.xml.XMLStatementBuilder$IncludeNodeHandler....
equivalence class clusters for NIL entities (those that could not be linked to an entity in the knowledge base), and entity type information for each of the queries. The data included in this ...
When right-clicking on an Entity Data Model .edmx file, the following context menu function is available: Generate Views. If you are looking for Reverse Engineeering tools, I recommend using the EF ...
报错信息:Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See ...
ENTITY FREQ_T IS PORT(CLK:IN STD_LOGIC FREQ_EN:OUT STD_LOGIC CNT_CLR:OUT STD_LOGIC Load:OUT STD_LOGIC) END FREQ_T
Create an Entity Data Model using the ADO.NET Entity Data Model Designer and the EdmGen tool Extend existing Entity Types to create your own Entity Types Write programs against the Entity Data Model ...
Data access is an integral part of any software application. Entity Framework provides a model-based system that makes data access effortless for developers by freeing you from writing similar data ...
Entity Framework 6 Recipes Entity Framework 6 Recipes
Ricardo Peres is a Portuguese developer, blogger, and occasionally an e-book author. He has more than 17 years of experience in software development, using technologies such as C/C++, Java, JavaScript...
Entity Framework 6 Recipes provides an exhaustive collection of ready-to-use code solutions for Entity Framework, Microsoft's model-centric, data-access platform for the .NET Framework and ASP.NET ...
Entity Developer Entity Developer Entity Developer
本书是关于Entity framework code first 的详细介绍,在本书中,你可以学到从无到有的创建基于Entity framework code first的项目
自留demo。springMVC-HttpEntity(ResponseEntity)与jQuery交互的小结demo。
电子书 Entity Framework 4 In Action
entityframework框架源代码,需要深入了解entityframework的同学可以下载深入学习研究
entity framework 基础介绍
ef entityframework服务端 封装dll
ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) 解决方案,早期被称为 ObjectSpace,现已经包含在 Visual Studio 2008 Service Pack 1 以及 .NET Framework 3.5 Service ...
entity framework 教程下载