20160510--hibernate懒加载问题
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.dzq.domain"> <class name="IDCard" table="id_card">
<id name="id" column="id">
<generator class="foreign">
<param name="property">person</param>
</generator>
<!-- <generator class="native"/> -->
</id>
<property name="name" column="name" />
<one-to-one name="person" constrained="true" lazy="proxy" fetch="join"/>
<!-- <many-to-one name="person" column="person_id" unique="true"/> -->
</class> </hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.dzq.domain"> <class name="Person" table="person">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" column="name" />
<one-to-one name="idcard"/>
<!-- <one-to-one name="idcard" property-ref="person"/> -->
</class> </hibernate-mapping>
多对一懒加载(影响性能,最好不禁用懒加载,使用hibernate初始化代理,解决)
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.dzq.domain"> <class name="Department" table="department">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="name" column="name" />
<!-- <set name="empls" cascade="save-update">
<key column="depart_id"/>
<one-to-many class="Employee"/>
</set> -->
<set name="empls" inverse="true">
<key column="depart_id"/>
<one-to-many class="Employee"/>
</set>
<!-- <list name="empls">
<key column="depart_id"/>
<list-index column="order_col"/>
<one-to-many class="Employee"/>
</list> --> <!-- <bag name="empls">
<key column="depart_id"/>
<one-to-many class="Employee"/>
</bag>
--> </class> </hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.dzq.domain"> <class name="Employee" table="employee" discriminator-value="0">
<id name="id" column="id">
<generator class="hilo" />
</id>
<!-- <discriminator column="type"/> -->
<property name="name" column="name" />
<many-to-one name="depart" column="depart_id" />
<!-- <subclass name="Skiller" discriminator-value="1">
<property name="skiller"/>
</subclass>
<subclass name="Sales" discriminator-value="2">
<property name="sell"/>
</subclass> -->
<!-- <joined-subclass name="Skiller" table="skiller">
<key column="emp_id"/>
<property name="skiller"/>
</joined-subclass>
<joined-subclass name="Sales" table="sales">
<key column="emp_id"/>
<property name="sell"/>
</joined-subclass> -->
<!-- <subclass name="Skiller" discriminator-value="1">
<property name="skiller"/>
</subclass>
<subclass name="Sales" discriminator-value="2">
<join table="sales">
<key column="emp_id"/>
<property name="sell"/>
</join> </subclass> -->
<union-subclass name="Skiller">
<property name="skiller"/>
</union-subclass>
<union-subclass name="Sales">
<property name="sell"/>
</union-subclass>
</class> </hibernate-mapping>
public static Department queryDepart(int id){
Session s=null;
try{
s=HibernateUntils.getSession();
Department depart=(Department) s.get(Department.class, id);
Hibernate.initialize(depart.getEmpls());//hibernate初始化代理
System.out.println(depart.getEmpls().getClass());
return depart;
}finally{
if(s!=null){
s.close();
}
}
}
多对多懒加载((更加影响性能,最好不禁用懒加载,使用hibernate初始化代理,解决))
20160510--hibernate懒加载问题的更多相关文章
- hibernate懒加载(转载)
http://blog.csdn.net/sanjy523892105/article/details/7071139 懒加载详解 懒加载为Hibernate中比较常用的特性之一,下面我们详细来了解下 ...
- 关于s2sh框架关于hibernate懒加载问题的说明和解决方案
首先我们来看下面这个图,解释了一个web程序的一次请求流程! 懒加载异常的说明: 懒加载就是我们在查询一个对象时,它所有的属性是否要被查出来! 如果懒加载开启的话,session在service层就被 ...
- Hibernate懒加载的三种解决方案
Hibernate懒加载的两种解决方案: 1.Hibernate.initialize(代理对象) 2.在*.hbm.xml映射文件中添加lazy="false"属性 3.使用op ...
- Hibernate懒加载解析
Hibernate懒加载解析 在Hibernate框架中,当我们要访问的数据量过大时,明显用缓存不太合适, 因为内存容量有限 ,为了减少并发量,减少系统资源的消耗,这时Hibernate用懒加载机制来 ...
- hibernate懒加载
Hibernate懒加载解析 hibernatejoinsession数据库sqlobject Hibernate懒加载解析 在Hibernate框架中,当我们要访问的数据量过大时,明显用缓存不太合适 ...
- 关于Hibernate懒加载问题的最终解决方案
看到一篇Hibernate懒加载的文章,所以转载,原地址如下: http://tuoxie007.iteye.com/blog/334853 Hibernate的强大之处之一是懒加载功能,可以有效的降 ...
- 【转】hibernate懒加载的问题,failed to lazily initialize a collection of role
hibernate懒加载的问题,failed to lazily initialize a collection of role hibernate懒加载的问题,failed to lazily in ...
- Hibernate懒加载深入分析
Hibernate懒加载深入分析 懒加载可以提高性能吗? 不可以简单的说"能",因为Hibernate的关系映射拖累了SQL的性能,所以想出懒加载来弥补.只是弥补而以,不会超越. ...
- -java转json hibernate懒加载造成的无限递归问题
1.在判断到底是谁维护关联关系时,可以通过查看外键,哪个实体类定义了外键,哪个类就负责维护关联关系. JoinColumn(name="pid") 2. 在保存数据时,总是先保存的 ...
- Hibernate懒加载导致json数据对象传输异常的问题---(非常重要)
1. 异常: [console_demo][WARN] [2016-12-15 19:49:35] org.springframework.web.servlet.mvc.support.Defaul ...
随机推荐
- Sort--快速排序
快速排序 1 public class QuickSort{ 2 3 public static int Partition(int[] a,int low,int high){ 4 int pivo ...
- 沈晓军 / LarvaFrame - 代码托管 - 开源中国社区
沈晓军 / LarvaFrame - 代码托管 - 开源中国社区 统计
- Project: Individual Project - Word frequency program----11061192zmx
Description & Requirements http://www.cnblogs.com/jiel/p/3311400.html 项目时间估计 理解项目要求: 1小时 构建项目逻辑: ...
- hdu 5586 Sum【dp最大子段和】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5586 Sum Time Limit: 2000/1000 MS (Java/Others) Me ...
- html标签应用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- MySQL订单分库分表多维度查询
转自:http://blog.itpub.net/29254281/viewspace-2086198/ MySQL订单分库分表多维度查询 MySQL分库分表,一般只能按照一个维度进行查询. 以订单 ...
- 基于EF创建数据库迁移
通过创建的实体类和DbContext类利用EF的Code First数据库迁移创建数据库. 下面看代码. 一.先创建实体类 我先添加一个BaseEntity,里面就一个属性 [Key] public ...
- Ubuntu 安装 Courier New字体
apt-get install ttf-mscorefonts-installer 它的本质是安装 Courier New字体 安装的时候会出现一个协议 按TAB键 ,可以选中<确定>按 ...
- jQuery中要注意的一些函数
has()方法 或 :has选择器 :是过滤子类含有的,并不是过滤当前选择器选择的元素或对象含有的
- Js_分页
public ActionResult Index(int? pageIndex) { List<string> data = new List<string>(); ; i ...