【发布时间】:2022-01-20 08:11:41
【问题描述】:
如何使用 jpa 查询从具有@OneToMany 关系的列中查找记录?
Post.class
public class Post {
@Id
private String id;
...
...
@OneToMany(cascade = CascadeType.ALL, mappedBy = "comment", fetch = FetchType.LAZY)
private Set<Comment> comments;
}
评论类
public class Comment {
...
...
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "comment", referencedColumnName = "id")
private Post post;
}
有什么方法可以查询PostRepository 并使用commentId 找到Post?
【问题讨论】:
标签: java spring-boot hibernate jpa spring-data-jpa