17

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.

blackpanther
  • 10,998
  • 11
  • 48
  • 78
SP M
  • 201
  • 2
  • 4
  • 9
  • Possible duplicate of [@OneToMany List<> vs Set<> difference](https://stackoverflow.com/questions/6562673/onetomany-list-vs-set-difference) – kaybee99 Apr 30 '18 at 22:01

2 Answers2

17

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.

Community
  • 1
  • 1
nolt2232
  • 2,594
  • 1
  • 22
  • 33
0
  1. we cannot assign duplicate value in Set but we can assign in List
  2. Insertion order not preserved in Set but preserved in List
Ponmudi VN
  • 1,493
  • 1
  • 18
  • 22