java @JoinFormula 和 @OneToMany 定义 - 糟糕的文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9954937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
@JoinFormula and @OneToMany definition - poor documentation
提问by Vojtěch
I have two questions concerning @JoinFormula and @OneToMany annotations:
我有两个关于 @JoinFormula 和 @OneToMany 注释的问题:
How can I limit the number of result with
@JoinFormula
and@OneToMany
annotations?How can I define that
id
in expressionauthor = id
refers toAuthor.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; }
如何限制结果
@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; }
Like this, I keep having the pastArticles empty, even when I remove the schedule <
part of the clause.
像这样,即使我删除schedule <
了子句的一部分,我仍然让过去的文章为空。
Thanks!
谢谢!
采纳答案by Jubin Patel
Answer 1 :
答案 1:
@Size(max=10)
private List<Comment> commentList;
Answer 2 :(just example like that)
答案 2 :(只是这样的例子)
public class A{
@Id
@GeneratedValue
private Integer id;
private String uuid;
...
}
other class
其他班级
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;
}
回答by Micha Roon
you'd be better off using the @Where
annotation to limit the results
你最好使用@Where
注释来限制结果