【问题标题】:@JoinFormula and @OneToMany definition - poor documentation@JoinFormula 和 @OneToMany 定义 - 糟糕的文档
【发布时间】:2012-04-14 20:16:27
【问题描述】:

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

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

  2. 如何定义表达式author = id 中的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 &lt; 部分,我仍然将过去的文章留空。

谢谢!

【问题讨论】:

标签: java hibernate persistence


【解决方案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 中的注释是如何协同工作的
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2017-10-16
    • 1970-01-01
    • 2014-09-07
    • 2010-09-06
    • 2011-11-26
    • 1970-01-01
    • 2022-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多