现在的位置: 首页 > 综合 > 正文

hibernate tree annotation

2018年03月29日 ⁄ 综合 ⁄ 共 2038字 ⁄ 字号 评论关闭
package entity.main;import java.util.Set;
import javax.persistence.CascadeType;import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import entity.ITree;
/** * menu for IE system * @author vivid * 2014-11-19 */
@Entity
@Table(name="ie_main_menu")
@GenericGenerator(name = "systemUUID", strategy = "uuid")
public class MainMenu{
	private String id; //identify node
//	private String parentId; //parent node's id
	private String text; //contents to display
	private String leaf; //0 false,1 means it's leaf
	private String iconCls;
	private String treeSign; // like "1-1,1-2-1"
	private String url;
	private MainMenu parent;
	private Set children;
	public MainMenu() {super();}
	
	@Id
	@GeneratedValue(generator="systemUUID")
	@Column(length=50)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	// public String getParentId() {
	// return parentId;
	// }
	// public void setParentId(String parentId) {// this.parentId = parentId;// }
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public String getLeaf() {
		return leaf;
	}
	public void setLeaf(String leaf) {
		this.leaf = leaf;
	}
	public String getIconCls() {
		return iconCls;
	}
	public void setIconCls(String iconCls) {
		this.iconCls = iconCls;
	}
	public String getTreeSign() {
		return treeSign;
	}
	public void setTreeSign(String treeSign) {
		this.treeSign = treeSign;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	//many children to one parent and the parentId is foreign key
	@ManyToOne 
	@JoinColumn(name="parentId") 
	public MainMenu getParent() {
		return parent;
	}
	public void setParent(MainMenu parent) {
		this.parent = parent;
	}
	//mappedBy indicates the many part's attribute
	@OneToMany(mappedBy="parent",cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	public Set getChildren() {
		return children;
	}
	public void setChildren(Set children) {
		this.children = children;
	}
}
//this is the first time to write blog. 

first to upload the code, wrong style and modify again

抱歉!评论已关闭.