Java Hibernate delayed loading and javahib.pdf Delay

Source: Internet
Author: User

Java Hibernate delayed loading and javahib.pdf Delay
Example data table: team (class), certificate (ID card), 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
-->
<Hibernate-mapping>
<Class name = "edu. dgut. ke. model. Team" table = "TEAM"Lazy = "true"> <! -- Multiple-to-one delayed loading settings -->
<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"> <! -- One-to-many delayed loading settings -->
<Key>
<Column name = "TEAMID" length = "32" not-null = "true"/>
</Key>
<One-to-define 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"
Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd>
<! --
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<Hibernate-mapping>
<Class name = "edu. dgut. ke. model. Certificate" table = "CERTIFICATE" Lazy = "true"> <! -- One-to-one delay loading settings -->

<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 delay loading settings -->

</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"
Http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd>
<! --
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>
<Certificate-to-one name = "certificate"
Class = "edu. dgut. ke. model. Certificate"
Unique = "true"
Column = "cardId"
Cascade = "all"
>
</Role-to-one>
<Role-to-one name = "team" class = "edu. dgut. ke. model. Team">
<Column name = "TEAMID" length = "32" not-null = "true"/>
</Role-to-one>
<Property name = "studentname" type = "java. lang. String">
<Column name = "STUDENTNAME" length = "16" not-null = "true" unique = "true"/>
</Property>
</Class>
</Hibernate-mapping>
Note: The delay loading of one-to-one relationships is slightly different from that of other relationships. Delayed-to-one loading is the class label in the configuration file
When lazy = "true" is set, lazy = "true" is set in the set label ". One-to-one does not only need
Set the tag to lazy = "true", and set constrained = "true" in the one-to-one tag ".
If constrained = "true" is not set, the default prefetch = "join" is used for one-to-one queries ").

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.