Java Hibernate deferred loading _java

Source: Internet
Author: User
Tags generator uuid
Sample datasheet: Team (Class), certificate (ID), Student (student)

Team.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" >
<!--
Mapping file autogenerated by MyEclipse persistence Tools
-->
<class name= "Edu.dgut.ke.model.Team" table= "Team" lazy = "true"><!--Multi-pair delay loading settings-->
<id name= "id" type= "java.lang.String" >
<column name= "ID" length= "/>"
<generator class= "Uuid.hex"/>
</id>
<property name= "Teamname" type= "java.lang.String" >
<column name= "Teamname" length= "not-null=" true "unique=" true "/>
</property>
<set name= "Students" inverse= "true" cascade= "all" lazy= "true"> <!--one-to-many delay-Loading settings-->
<key>
<column name= "Teamid" length= "not-null=" "true"/>
</key>
<one-to-many class= "Edu.dgut.ke.model.Student"/>
</set>
</class>

Certificate.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" >
<!--
Mapping file autogenerated by MyEclipse persistence Tools
-->
<class name= "edu.dgut.ke.model.Certificate" table= "certificate" lazy= "true" ><!--a one-to-one delay-loading setting-->

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

</generator>
</id>
<property name= "describe" type= "java.lang.String" >
<column name= "' DESCRIBE '" length= "not-null=" true "/>
</property>
<one-to-one name= "Student"
Class= "Edu.dgut.ke.model.Student"
constrained= "true"><!--a one-to-one delay-loading setting-->

</one-to-one>
</class>

Student.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" >
<!--
Mapping file autogenerated by MyEclipse persistence Tools
-->
<class name= "edu.dgut.ke.model.Student" table= "Student"Lazy= "true">
<id name= "id" type= "java.lang.String" >
<column name= "ID" length= "/>"
<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= "not-null=" "true"/>
</many-to-one>
<property name= "Studentname" type= "java.lang.String" >
<column name= "Studentname" length= "not-null=" true "unique=" true "/>
</property>
</class>
Note: Deferred loading of one-to-one relationships is slightly different than other relationships. Many-to-one Delay loading is the class tag in the configuration file
Set lazy= "True" on, One-to-many and Many-to-many delay loading is set lazy= "true" in the set label. and one-to-one not just in classs
The label setting is Lazy= "true" and you want to set constrained= "true" in the One-to-one tab.
If you do not set constrained= "true", the one-to-one query uses the default pre-crawl policy (fetch= "join").

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.