一尘不染

@JoinFormula和@OneToMany定义-较差的文档

hibernate

我有两个有关@JoinFormula和@OneToMany批注的问题:

  1. 如何限制带有@JoinFormula@OneToMany注释的结果数?

  2. 如何定义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为空。

谢谢!


阅读 909

收藏
2020-06-20

共1个答案

一尘不染

答案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;      
}
2020-06-20