hibernate JPA 單表樹形結構 註解配置
阿新 • • 發佈:2019-01-04
public class Category implements java.io.Serializable {
@Id
@GeneratedValue(strategy=IDENTITY)
@Column(name="CAT_ID", unique=true, nullable=false)
private Integer id;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="CAT_PARENT_ID")
private Category parent;
@Column(name="CAT_NAME", nullable=false, length=50)
private String name;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="parent ")
private Set<Category> children = new HashSet<Category>(0);
//省略getter/setter
@Id
@GeneratedValue(strategy=IDENTITY)
@Column(name="CAT_ID", unique=true, nullable=false)
private Integer id;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="CAT_PARENT_ID")
private Category parent;
@Column(name="CAT_NAME", nullable=false, length=50)
private String name;
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="parent
private Set<Category> children = new HashSet<Category>(0);
//省略getter/setter
}