Use hibernate to recursively

xiaoxiao2021-03-06  39

At work, we often encounter data with recursive nature records, the most common is the data of a mechanism department node, and a node will have a parent node attribute, and it may have several sub-nodes. All node data exists in a table in the database. This phenomenon is called Composite mode in the design mode.

Let me give an example of operating this table with hibernate. For the part of the Hibernate configuration and establishment of the table structure, please refer to my previous article "Use WebLogic data source as an example of the data source of Hibernate 1. Persistence Class node.javaPackage com.jagie.business.organization; / ** *

Title: *

Description: Department Node *

Copyright: CopyRight (C) 2003 *

company: www.jagie.com * @Author jagie * @version 1.0 * / public class node {private string id; // pk private string name; // Name Private string description; / / Describe the private node parent; // superior department private java.util.set children; // lower department public static void main (string [] args) {} public string getId () {returnid;} 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 = pent;} public string getdescription;} public void setdescription; {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. Map file node.hbm.xml [pre]? xml version = '1.0' encoding = 'UTF-8'?> " Hongernate- Mapping> 转载请注明原文地址:https://www.9cbs.com/read-64836.html


New Post(0)