浏览 2099 次
锁定老帖子 主题:如何实现Hibernate树行结构的删除
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-03-14
下边是部分结构说明 CstBomMasterTest.hbm.xml <hibernate-mapping> <class name="test.CstBomMasterTest" table="CST_BOM_MASTER_TEST" schema="CAPMS"> <id name="id" type="long" column="ID"> <generator class="increment" /> </id> <property name="code" type="string"> <column name="CODE" length="20" /> </property> <property name="name" type="string"> <column name="NAME" length="20" /> </property> <!-- <property name="parentCode" type="string"> <column name="PARENT_CODE" length="20" /> </property>--> <set name="childCstBomMasterTests" cascade="all" inverse="true"> <key column="parent_code" /> <one-to-many class="test.CstBomMasterTest" /> </set> <many-to-one name="parentCstBomMasterTest" column="parent_code" class="test.CstBomMasterTest" cascade="all" /> </class> </hibernate-mapping> java类文件 public class CstBomMasterTest implements java.io.Serializable { private Long id; private String code; private String name; private CstBomMasterTest parentCstBomMasterTest; private Set childCstBomMasterTests = new HashSet(); public CstBomMasterTest(String code, String name, CstBomMasterTest parentCstBomMasterTest, Set childCstBomMasterTests) { this.code = code; this.name = name; this.parentCstBomMasterTest = parentCstBomMasterTest; this.childCstBomMasterTests = childCstBomMasterTests; } public CstBomMasterTest() { } public CstBomMasterTest(Set childCstBomMasterTests) { this.childCstBomMasterTests = childCstBomMasterTests; } public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } public String getCode() { return this.code; } public void setCode(String code) { this.code = code; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public CstBomMasterTest getParentCstBomMasterTest() { return this.parentCstBomMasterTest; } public void setParentCstBomMasterTest( CstBomMasterTest parentCstBomMasterTest) { this.parentCstBomMasterTest = parentCstBomMasterTest; } public Set getChildCstBomMasterTests() { return this.childCstBomMasterTests; } public void setChildCstBomMasterTests(Set childCstBomMasterTests) { this.childCstBomMasterTests = childCstBomMasterTests; } public void addChildCstBomMasterTest(CstBomMasterTest cstBomMasterTest) { if (cstBomMasterTest == null) throw new IllegalArgumentException( "Can't add a null cstBomMasterTest as child."); // Remove from old parent category if (cstBomMasterTest.getParentCstBomMasterTest() != null) cstBomMasterTest.getParentCstBomMasterTest() .getChildCstBomMasterTests().remove(cstBomMasterTest); // Set parent in child cstBomMasterTest.setParentCstBomMasterTest(this); // Set child in parent this.getChildCstBomMasterTests().add(cstBomMasterTest); } public String toString() { return new ToStringBuilder(this).append("id", getId()).toString(); } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |