Hibernate @OrderBy with referenced class

前端 未结 4 885
广开言路
广开言路 2021-01-12 23:34

I have a class say: \"ClassA\" which has a collection of \"ClassB\"

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = \"COLUMN         


        
相关标签:
4条回答
  • 2021-01-13 00:01

    use @Sort with custom comparator instead

    0 讨论(0)
  • 2021-01-13 00:03

    It's unfortunately impossible to do what you want. I've answered a similar question here.

    @OrderBy only supports direct properties of the collection elements.

    0 讨论(0)
  • 2021-01-13 00:04

    This is possible if you use JPA. See this article.

    Then you just add @OrderBy("name") to the collection property

    0 讨论(0)
  • 2021-01-13 00:10

    I only know NHibernate (.NET version), but I guess it should work similar:

    @OrderBy(clause = "name asc")  
    

    Or you can try this:

    @OrderBy("name")  
    
    0 讨论(0)
提交回复
热议问题