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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9954937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:02:39  来源:igfitidea点击:

@JoinFormula and @OneToMany definition - poor documentation

javahibernatepersistence

提问by Vojtěch

I have two questions concerning @JoinFormula and @OneToMany annotations:

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

  1. How can I limit the number of result with @JoinFormulaand @OneToManyannotations?

  2. How can I define that idin expression author = idrefers to 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;
    }
    
  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;
    }
    

Like this, I keep having the pastArticles empty, even when I remove the schedule <part of the clause.

像这样,即使我删除schedule <了子句的一部分,我仍然让过去的文章为空。

Thanks!

谢谢!

采纳答案by Jubin Patel

Answer 1 :

答案 1:

@Size(max=10)
private List<Comment> commentList;

Answer 2 :(just example like that)

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

public class A{

    @Id
    @GeneratedValue
    private Integer id;

    private String uuid;

    ...
  }

other class

其他班级

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

回答by Micha Roon

you'd be better off using the @Whereannotation to limit the results

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