There are many questions on stackoverflow that speaks about using List
vs Set
in Hibernate entities. My question is slightly different (or may be same, but I am not able to understand it yet).
If I read the Hibernate docs, they recommend to use Set
for many-valued associations here http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/#persistent-classes-equalshashcode.
Quoting from above documentation link:
You have to override the equals() and hashCode() methods if you:
- intend to put instances of persistent classes in a Set (the recommended way to represent many-valued associations);
- and intend to use reattachment of detached instances
That was till Hibernate 4.3. But in later versions, I don't see that statement anymore (http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#mapping-model-pojo-equalshashcode)
So my questions are
- why did Hibernate recommended to use
Set
instead ofList
till Hibernate 4? - Since I don't see that recommendation in Hibernate 5, does it mean that it is not valid anymore?
Thanks!!