hibernate中延迟加载的设定(懒加载的设定)

User.hbm.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.shiryu.otm.User" table="user" batch-size="5" lazy="false" dynamic-update="true" dynamic-insert="true"   >
    <!-- 为集合类型中的实体也指定缓存策略 -->
    <cache usage="read-write" />
    <id name="id" type="java.lang.Integer">
      <column name="id" />
      <generator class="native" />
    </id>
      <!-- 为集合类设定缓存 -->
      <cache usage="read-write" />
      <key column="user_id"></key>
      <on e-to-many class="com.shiryu.otm.Address" />
    </set>
</class>
</hibernate-mapping>

LazyLoadingTest.java:


package com.shiryu.otm;

imp ort java.util.Collection;
imp ort java.util.Iterator;
imp ort java.util.List;

imp ort org.hibernate.Query;
imp ort org.hibernate.Session;
imp ort org.hibernate.SessionFactory;
imp ort org.hibernate.cfg.Configuration;

public class LazyLoadingTest {
    // 延迟加载 Lazing Loading
    // 所谓延迟加载,就是在数据需要的时候,才真正执行数据加载操作
    // hibernate 3 中延迟加载实现主要针对:1.实体对象 2.集合(Collection) 3.属性延迟加载

    public static void main(String[] args) {
        SessionFactory factory = new

你可能感兴趣的:(Hibernate,延迟加载,懒加载)