Hibernate Set Or List

2019-06-15 07:46发布

问题:

Can anybody know when to use Set and when to use List in hibernate mapping file ?

<set name="" table="">
    <key>
        <column name="" />
    </key>
</set>


<list name="" cascade="all">
    <key column="" />
    <index column="" />
    <one-to-many class=""/>
</list>

Thanks.

回答1:

Take a look at this post: @OneToMany List<> vs Set<> difference

The main difference is that a list has ordering while a set does not. Also, a set cannot have duplicate values, while a list can.