Voj*_*ěch 28 java persistence hibernate
我有两个关于@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;
}
Run Code Online (Sandbox Code Playgroud)像这样,即使我删除schedule <了条款的一部分,我仍然将pastArticles保持为空.
谢谢!
Jub*_*tel 14
答案1:
@Size(max=10)
private List<Comment> commentList;
Run Code Online (Sandbox Code Playgroud)
答案2 :(就是这样的例子)
public class A{
@Id
@GeneratedValue
private Integer id;
private String uuid;
...
}
Run Code Online (Sandbox Code Playgroud)
其他课程
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14348 次 |
| 最近记录: |