@JoinFormula和@OneToMany定义 - 文档记录不佳

2022-09-01 09:03:23

关于@JoinFormula和@OneToMany注释,我有两个问题:

  1. 如何使用和注释限制结果的数量?@JoinFormula@OneToMany

  2. 我如何定义表达式中的引用?idauthor = idAuthor.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 <

谢谢!


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

答案 2

您最好使用注释来限制结果@Where


推荐