带嵌套字段的java Spring数据查询(连接其他列)
我有三个实体
Topic
,Text
和Author
Topic 1:n Text and Text 1:n Author
我的实体看起来像这样:
@Entity
public class Topic {
@Id
private int id;
private LocalDate date;
private String name;
@JoinColumn(name = "text_id", nullable = false)
private Text text;
}
@Entity
public class Text {
@Id
private int id;
private LocalDate date;
private String name;
private String description;
@JoinColumn(name = "author_id", nullable = false)
private Author author;
}
public class Author{
@Id
private int id;
private String name;
private String description;
}
现在,我尝试创建spring数据jpa查询,以获取特定作者日期之间的主题
解决方案仅适用于工作之间的日期:
List<Topic> findByDateBetween(LocalDate begin, LocalDate end);
我试过这样的方法:
List<Topic> findByDateBetween_AuthorId(LocalDate begin, LocalDate end, int authorId);
List<Topic> findByDateBetweenAuthorId(LocalDate begin, LocalDate end, int authorId);
List<Topic> findByDateBetweenAuthor_id(LocalDate begin, LocalDate end, int authorId);
什么都没用。有什么建议吗
# 1 楼答案
在主题的JPA存储库中,您可以编写自定义查询