<?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" >
<hibernate-mapping default-lazy="false">
<class name="entity.Keyword" table="keyword">
<id name="keywordId" column="keyword_id">
<generator class="increment" />
</id>
<property name="title" column="title" />
<property name="body" column="body" />
<property name="lastModifiedTime" column="last_modified_time" />
<property name="createTime" column="create_time" />
<set name="parents" table="keyword_to_keyword" cascade="none" lazy="false">
<key column="child_id"/>
<many-to-many column="parent_id" class="entity.Keyword" />
</set>
<set name="children" table="keyword_to_keyword" cascade="none" lazy="false">
<key column="parent_id"/>
<many-to-many column="child_id" class="entity.Keyword" />
</set>
</class>
</hibernate-mapping>
We simply tell Hibernate that keyword_to_keyword has a column 'parent_id' that refers to another Keyword, joined by keyword_id column, as the parent. and it has a column 'child_id' that refers to another Keyword as the child. Since a keyword can have many parents and/or children this is a many-to-many mapping! Questions? Let me know!
◀ Create Java ClassTest Java Code ▶
0 komentar:
Posting Komentar