@OneToMany List<> vs Set<> difference

后端 未结 2 1980
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 02:32

Is there any difference if I use

@OneToMany
public Set ratings;

or if I use

@OneToMany
public List

        
2条回答
  •  悲哀的现实
    2020-11-28 03:14

    If you use a List, then you can specify an 'Order BY' clause in getter function. You can't do that with a Set. The order by clause can contain partial EJBQL; For example

    @OneToMany
    @OrderBy("lastname ASC")
    public List ratings;
    

    If you leave this field blank, then the list is sorted in ascending order based on the value of the primary key.

提交回复
热议问题