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

时间:2012-03-31 10:03:07

标签: java hibernate persistence

我有两个关于@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;
    }
    
  3. 像这样,即使我删除了条款的schedule <部分,我仍然将pastArticles保持为空。

    谢谢!

2 个答案:

答案 0 :(得分:12)

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

答案 1 :(得分:1)

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