我有两个有关@JoinFormula和@OneToMany批注的问题:
如何限制带有@JoinFormula和@OneToMany注释的结果数?
@JoinFormula
@OneToMany
如何定义id表达式中author = id所指的Author.id?
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为空。
schedule <
谢谢!
答案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; }