hibernate中,一个类自关联,注解怎么写?
@Entity@Table(name="T_MENU")publicclassMenuextendsBaseObjectimplementsSerializable{pr...
@Entity
@Table(name="T_MENU")
public class Menu extends BaseObject implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@Id
@Column(name = "PK_ID")
private String id;
/**
* 菜单名
*/
@Column(name = "F_MENU_NAME")
private String menuName;
/**
* URL请求(功能)
*/
@Column(name = "F_ACTION")
private String action;
/**
* 所属父节点
* FK_BELONG_ID
*/
@ManyToOne(fetch = FetchType.LAZY)
@LazyToOne(LazyToOneOption.PROXY)
@JoinColumn(name = "FK_BELONG_ID")
private Menu parentMenu;
/**
* 子节点
*/
@OneToMany(fetch = FetchType.LAZY,cascade = CascadeType.ALL, mappedBy = "parentMenu")
@LazyCollection(LazyCollectionOption.TRUE)
private Set<Menu> childMenus;
......
} 展开
@Table(name="T_MENU")
public class Menu extends BaseObject implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@Id
@Column(name = "PK_ID")
private String id;
/**
* 菜单名
*/
@Column(name = "F_MENU_NAME")
private String menuName;
/**
* URL请求(功能)
*/
@Column(name = "F_ACTION")
private String action;
/**
* 所属父节点
* FK_BELONG_ID
*/
@ManyToOne(fetch = FetchType.LAZY)
@LazyToOne(LazyToOneOption.PROXY)
@JoinColumn(name = "FK_BELONG_ID")
private Menu parentMenu;
/**
* 子节点
*/
@OneToMany(fetch = FetchType.LAZY,cascade = CascadeType.ALL, mappedBy = "parentMenu")
@LazyCollection(LazyCollectionOption.TRUE)
private Set<Menu> childMenus;
......
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询