看下我的这个帖子,用hibernate实现树状结构。
http://blog.csdn.net/pizzame/archive/2007/10/09/1816811.aspx
http://blog.csdn.net/pizzame/archive/2007/10/09/1816811.aspx
解决方案 »
- 使用struts2标签时遇到了以下问题,怎么解决
- spring 3.0.5所需jar
- oracle数据库字段
- Jbpm4.3,学习中碰到问题,关于family168 的jbpm4教程
- hibernate如何写更新语句?
- struts2上传问题
- tomcat的work文件夹下的tldCache.ser??
- 启动glassfish2服务器时报异常java.lang.ClassNotFoundException:com.sun.ejb.containers.TimerBean_2100919770_ConcreteImpl
- [struts]请问在validator中,如何调用非默认资源文件中的内容?
- 关于用jdbc oci驱动jdbc thin驱动连数据库的问题
- 请解释unsaved-value的意思
- hibernate主从表的问题
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;@Entity
public class Department {
private int id;
private Department parent;
private Set<Employee> children; //通过Set将下级加入该实体 private String name;
private boolean isRoot;
private String description;// 备注
public Department() { }
@OneToMany(cascade = CascadeType.ALL,mappedBy ="parent" )
public Set<Employee> getChildren() {
return children;
} public void setChildren(Set<Employee> children) {
this.children = children;
} @Id
@GeneratedValue(strategy = GenerationType.TABLE)
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} @ManyToOne
@JoinColumn
public Department getParent() {
return parent;
}
public void setParent(Department parent)
{
this.parent = parent;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public boolean isRoot() {
return isRoot;
} public void setRoot(boolean isRoot) {
this.isRoot = isRoot;
} public String getDescription() {
return description;
} public void setDescription(String description) {
this.description = description;
} @Transient
public boolean isTransient() {
return getId() < 1;
}}
pizzame
结贴package shadowingfly;import java.util.Set;import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Transient;@Entity
public class Department {
private int id;
private Department parent;
private Set<Department> children; //通过Set将下级加入该实体 private String name;
private boolean isRoot;
private String description;// 备注
public Department() { }
@OneToMany(cascade = CascadeType.ALL,mappedBy ="parent" )
public Set<Department> getChildren() {
return children;
} public void setChildren(Set<Department> children) {
this.children = children;
} @Id
@GeneratedValue(strategy = GenerationType.TABLE)
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} @ManyToOne
@JoinColumn
public Department getParent() {
return parent;
}
public void setParent(Department parent)
{
this.parent = parent;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public boolean isRoot() {
return isRoot;
} public void setRoot(boolean isRoot) {
this.isRoot = isRoot;
} public String getDescription() {
return description;
} public void setDescription(String description) {
this.description = description;
} @Transient
public boolean isTransient() {
return getId() < 1;
}}