同一实体上的 JPA 父子关系(视图)
我有一个观点,它有亲子关系。所以我的实体是这样的:
@Entity
@Table(name = "assessment_v", schema = "hlt_hrsc")
public class HrscLabellingAssessmentVEntity {
@Id
private String id;
@Column(name = "child_id")
private String childId;
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name = "id")
private HrscLabellingAssessmentVEntity parent;
@OneToMany(mappedBy = "parent")
private Set<HrscLabellingAssessmentVEntity> child = new HashSet<>();
}
当我启动我的应用程序时,它会抛出一个错误: 嵌套异常是org.hibernate.MappingException:无法确定类型:java.util.Set
请找到父子视图的下图,例如:
id child_id
120.35871 120.35872
120.35872 null
这里120.35872是父记录,120.35871是儿童记录。 ParentId 维护在 child_id 列中。我的要求是,当我尝试获取父记录时,它也应该有子记录。
我做错了什么?
I have a view which has a parent-child relationship. So I have my entity this way:
@Entity
@Table(name = "assessment_v", schema = "hlt_hrsc")
public class HrscLabellingAssessmentVEntity {
@Id
private String id;
@Column(name = "child_id")
private String childId;
@ManyToOne(cascade = {CascadeType.ALL})
@JoinColumn(name = "id")
private HrscLabellingAssessmentVEntity parent;
@OneToMany(mappedBy = "parent")
private Set<HrscLabellingAssessmentVEntity> child = new HashSet<>();
}
when I start my application it throws an error :
nested exception is org.hibernate.MappingException: Could not determine type for: java.util.Set
Please find the below image of the view for parent child eg:
id child_id
120.35871 120.35872
120.35872 null
Here 120.35872 is the parent record and 120.35871 is the child record. The parentId is maintained on the child_id column. My requirement is when I try to fetch the parent it should have the child records also.
what am I doing wrong??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请检查这个例子
Please check this example