1.持久化类Node.java
- package com.jagie.business.organization;
- /**
- *
Title:
- *
Description: 部门节点
- *
Copyright: Copyright (c) 2003
- *
Company: www.jagie.com
- * @author Jagie
- * @version 1.0
- */
- public class Node {
- private String ID;//pk
- private String name;//名称
- private String description;//描述
- private Node parent;//上级部门
- private java.util.Set children;//下级部门
- public static void main(String[] args) {
- }
- public String getID() {
- return ID;
- }
- public void setID(String ID) {
- this.ID = ID;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public Node getParent() {
- return parent;
- }
- public void setParent(Node parent) {
- this.parent = parent;
- }
- public String getDescription() {
- return description;
- }
- public void setDescription(String description) {
- this.description = description;
- }
- public String toString(){
- return name;
- }
- public java.util.Set getChildren() {
- return children;
- }
- public void setChildren(java.util.Set children) {
- this.children = children;
- }
- }
2.映射文件Node.hbm.xml
column="parent" name="parent" />
3.用SchemaExport创建数据库(略)
4.测试的代码片断
- //获取net.sf.hibernate.Session和net.sf.hibernate.Transaction;
- Session s = JDOUtils.getInstance().getSessionFactory().openSession();
- Transaction t = s.beginTransaction();
- //建立父节点
- Node org = new Node();
- org.setName("北京总公司");
- org.setDescription("这是北京总公司");
- //建立子节点
- Node org2 = new Node();
- org2.setName("海淀分公司");
- org2.setDescription("这是海淀分公司");
- //建立子节点对父节点的引用
- org2.setParent(org);
- &