I have two questions concerning @JoinFormula and @OneToMany annotations:
How can I limit the number of result with
@JoinFormulaand@OneToManyannotations?How can I define that
idin expressionauthor = idrefers 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; }
Like this, I keep having the pastArticles empty, even when I remove the schedule < part of the clause.
Thanks!
Answer 1 :
@Size(max=10)
private List<Comment> commentList;
Answer 2 :(just example like that)
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;
}
you'd be better off using the @Where annotation to limit the results
来源:https://stackoverflow.com/questions/9954937/joinformula-and-onetomany-definition-poor-documentation