【发布时间】:2014-11-27 05:15:22
【问题描述】:
我想在数据库中存储分层文件夹。 F.e
@Entity
public class Folder {
int id
String name
Folder parentFolder
}
因此,如果文件夹在子文件夹中,他应该存储有关 parentFolder 的信息 如果文件夹在根/顶级文件夹中,它没有任何父文件夹,所以会有空
我应该如何使用注释设置休眠来实现这一点?
我的实体类:
@Entity
@Table(name="common__Role")
public class Role {
/** The id. */
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
/**
* Parent Role id.
*/
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="ROLE_ID")
public Role role;
/** The name. */
@Constraints.Required
public String name;
【问题讨论】:
-
这是一个
@OneToMany和一个@ManyToOnerelation,所以你应该这样处理。
标签: java hibernate jpa orm annotations