The first step is to write a comment:
<!--xx attribute, this class and yy (Class) of the many-to-one
<!--xx attribute, this class is one-to-many with yy (class)
<!--xx attribute, many-to-many for this class and yy (Class)---
<!--xx attribute, one-to-one with YY (class)
Part Two, copy template
<!--xx attribute, this class and yy (Class) of the many-to-one
<many-to-one name= "" class= "" column= "" ></many-to-one>
<!--xx attribute, this class is one-to-many with yy (class)
<set name= "" >
<key column= "" ></key>
<one-to-many class= ""/>
</set>
<!--xx attribute, many-to-many for this class and yy (Class)---
<set name= "" table= "" >
<key column= "" ></key>
<many-to-many class= "" column= "" ></many-to-many>
</set>
<!--xx attribute, one-to-one with YY (class)
<many-to-one name= "" class= "" column= "" unique= "true" ></many-to-one>
The third step, fill in the blanks:
<!--xx attribute, this class and yy (Class) of the many-to-one
<many-to-one name= "xx" class= "Yy" column= "" ></many-to-one>
<!--xx attribute, this class is one-to-many with yy (class)
<set name= "XX" >
<key column= "" ></key>
<one-to-many class= "Yy"/>
</set>
<!--xx attribute, many-to-many for this class and yy (Class)---
<set name= "xx" table= "" >
<key column= "" ></key>
<many-to-many class= "Yy" column= "" ></many-to-many>
</set>
<!--xx attribute, one-to-one with YY (class)
<many-to-one name= "xx" class= "Yy" column= "" unique= "true" ></many-to-one>
Description
Many-to-one, a-to-many column's name is taken by itself, but the corresponding two column of the two relations must be the same;
Generally in many parties, the attribute name +id as the column value, a pair of more than one side also use this column, so it is possible;
Many-to-many, tables is a multi-to-many intermediate table in general naming that includes two table names. The column in key is worth the set foreign key, referring to the foreign key referencing the current table, this object is +id. Many-to-many refers to the foreign key referring to each other, the General association object name +id;
Here's an example:
Entity class:
Role
/** * Entity: Post * @author Jelly * */public class Role implements serializable{private Long id;private String name;private set<user> users = new hashset<user> ();
Hbn.xml
User:
/** * Entity: User * @author Jelly * */public class User implements Serializable{private Long id;private Department departmen t;//Department Private set<role> roles = new hashset<role> ();}
User.hbm.xml
Department/** * Entity: Department * @author Jelly */public class Department implements Serializable{private Long id;private set<user> User s = new hashset<user> ();p rivate Department parent;private set<department> children = new hashset< Department> ();}
Department.hbm.xml