我有两个关于@JoinFormula和@OneToMany注释的问题:
如何使用@JoinFormula
和@OneToMany
注释限制结果数量?
如何定义表达式id
中的author = id
引用Author.id
?
Author {
@Id
private Long id;
@OneToMany
@JoinFormula(value = "SELECT a FROM Article a WHERE author = id AND schedule < CURRENT_TIMESTAMP()") // limit = 15
private List<Article> pastArticles;
}
像这样,即使我删除了条款的schedule <
部分,我仍然将pastArticles保持为空。
谢谢!
答案 0 :(得分:12)
答案1:
@Size(max=10)
private List<Comment> commentList;
答案2 :(就是这样的例子)
public class A{
@Id
@GeneratedValue
private Integer id;
private String uuid;
...
}
其他班级
public class B{
@Id
@GeneratedValue
private Integer id;
private String uuidOfA;
@ManyToOne
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(formula=@JoinFormula(value="(SELECT a.id FROM A a WHERE a.uuid = uuid)", referencedColumnName="id")),
@JoinColumnOrFormula(column = @JoinColumn("uuidOfA", referencedColumnName="uuid"))
})
private A a;
}
答案 1 :(得分:1)
您最好使用@Where
注释来限制结果