a)java代码
public class DefaultFile {
private Set tagSet;
………………………………
/**
*
* @author weip
* @return
* @time 2006-1-13 13:48:29
*
* @hibernate.set lazy="true" cascade="save-update" table="FileTagRel"
* @hibernate.collection-key column="fileId"
* @hibernate.collection-many-to-many class="mofile.share.domain.FileTag"
* column="tagId"
*/
public Set getTagSet() {
return tagSet;
}
…………………………...
}
public class DefaultUser{
private Set allFileSet;
…………………………………..
/**
*
* @author weip
* @return
* @time 2006-1-13 13:18:35
*
* @hibernate.set
* lazy="true"
* cascade="all-delete-orphan"
* @hibernate.collection-key
* column="userId"
* @hibernate.collection-one-to-many
* class="mofile.share.domain.DefaultFile"
*/
public Set getAllFileSet() {
return allFileSet;
}
……………………………………...
}
b)映射文件
DefaultFile.hbm.xml
…………………..
<set
name="tagSet"
table="FileTagRel"
lazy="true"
cascade="all"
sort="unsorted"
>
<key
column="fileId"
>
</key>
<many-to-many
class="mofile.share.domain.FileTag"
column="tagId"
outer-join="auto"
/>
</set>
…………………..
FileTag.hbm.xml
…………………..
<set
name="fileSet"
table="FileTagRel"
lazy="true"
cascade="none"
sort="unsorted"
>
<key
column="tagId"
>
</key>
<many-to-many
class="mofile.share.domain.DefaultFile"
column="fileId"
outer-join="auto"
/>
</set>
…………………..
c)数据库
4)Dao
public void saveObject(Object o) {
getHibernateTemplate().saveOrUpdate(o);
}