@JoinFormula和@OneToMany定义 - 糟糕的文档

Voj*_*ěch 28 java persistence 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;
    }
    
    Run Code Online (Sandbox Code Playgroud)

像这样,即使我删除schedule <了条款的一部分,我仍然将pastArticles保持为空.

谢谢!

Jub*_*tel 14

答案1:

@Size(max=10)
private List<Comment> commentList;
Run Code Online (Sandbox Code Playgroud)

答案2 :(就是这样的例子)

public class A{

    @Id
    @GeneratedValue
    private Integer id;

    private String uuid;

    ...
  }
Run Code Online (Sandbox Code Playgroud)

其他课程

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;      
}
Run Code Online (Sandbox Code Playgroud)

  • 一些解释会很好.我知道我可能太傻了,但我不明白答案2中的注释是如何协同工作的 (4认同)