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 ").