8535.com-新浦京娱乐场官网|欢迎您

新浦京娱乐场官网java Hibernate延迟加载,javahibe

来源:http://www.dnamique.com 作者:计算机网络 人气:110 发布时间:2019-10-07
摘要:java Hibernate延迟加载,javahibernate延迟 示例数据表:team(班级)、certificate(身份证)、student(学生) Team.hbm.xml ?xml version="1.0" encoding="utf-8"? !DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate MappingDT

java Hibernate延迟加载,javahibernate延迟

示例数据表:team(班级)、certificate(身份证)、student(学生)
新浦京娱乐场官网 1
Team.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
新浦京娱乐场官网,";
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="edu.dgut.ke.model.Team" table="TEAM" lazy ="true" ><!-- 多对一的延迟加载设置 -->
        <id name="id" type="java.lang.String">
            <column name="ID" length="32" />
            <generator class="uuid.hex" />
        </id>
        <property name="teamname" type="java.lang.String">
            <column name="TEAMNAME" length="32" not-null="true" unique="true" />
        </property>
        <set name="students" inverse="true" cascade="all" lazy="true" > <!-- 一对多的延迟加载设置 -->
            <key>
                <column name="TEAMID" length="32" not-null="true" />
            </key>
            <one-to-many class="edu.dgut.ke.model.Student" />
        </set>
    </class>
</hibernate-mapping>

Certificate.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
";
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="edu.dgut.ke.model.Certificate" table="CERTIFICATE" lazy="true" ><!-- 一对一的延迟加载设置 -->

        <id name="id" type="java.lang.String">
            <column name="ID" length="32" />
            <generator class="uuid">

            </generator>
        </id>
        <property name="describe" type="java.lang.String">
            <column name="`DESCRIBE`" length="50" not-null="true" />
        </property>
        <one-to-one name="student"
        class="edu.dgut.ke.model.Student"
         constrained="true" ><!-- 一对一的延迟加载设置 -->

        </one-to-one>
    </class>
</hibernate-mapping>

Student.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
";
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="edu.dgut.ke.model.Student" table="STUDENT" lazy="true" >
        <id name="id" type="java.lang.String">
            <column name="ID" length="32" />
            <generator class="uuid.hex" />
        </id>
        <many-to-one name="certificate"
        class="edu.dgut.ke.model.Certificate"
        unique="true"
        column="cardId"
        cascade="all"
        >
        </many-to-one>
        <many-to-one name="team" class="edu.dgut.ke.model.Team">
            <column name="TEAMID" length="32" not-null="true" />
        </many-to-one>
        <property name="studentname" type="java.lang.String">
            <column name="STUDENTNAME" length="16" not-null="true" unique="true" />
        </property>
    </class>
</hibernate-mapping>
注意:对one-to-one 关系进行延迟加载和其他关系相比稍微有些不同。many-to-one 的延迟加载是在配置文件的class 标签
上设置 lazy="true" ,one-to-many 和 many-to-many 的延迟加载是在 set 标签中设置lazy="true"。而one-to-one 不只要在 classs
标签设置 lazy="true",而且要在one-to-one 标签中设置constrained="true" 。
如果不设置constrained="true",则一对一查询使用默认的预先抓取策略(fetch="join")。

Hibernate延迟加载,javahibernate延迟 示例数据表:team(班级)、certificate(身份证)、student(学生) Team.hbm.xml ?xml version="1.0" encoding="utf-8"? !DOCTYP...

本文由8535.com-新浦京娱乐场官网|欢迎您发布于计算机网络,转载请注明出处:新浦京娱乐场官网java Hibernate延迟加载,javahibe

关键词:

频道精选

最火资讯