Choosing ListSematics in Hibernate 6
Вставка
- Опубліковано 17 гру 2024
- Based on its javadoc, a java.util.List is supposed to represent an ordered collection of values. But that’s not necessarily the case if you use it as the type of a to-many association or an ElementCollection. As I explained before, Hibernate can handle a java.util.List as a Bag or a List. Only the List mapping persists the order of its elements. But by default, Hibernate handles a java.util.List as a Bag. After you have fetched it from the database, it contains the elements in an undefined order.
Until Hibernate 6.0.0, you had to add an @OrderColumn annotation to your ElementCollection, one-to-many association, or the owning side of your many-to-many association to persist the order of your java.util.List. Hibernate then persists the position of each element in a separate column and manages the index of all elements during all insert, update, and delete operations.
Since Hibernate 6, you can define the List semantics globally for the owning side of your many-to-many associations and ElementCollections by setting the configuration property hibernate.mapping.default_list_semantics to LIST in your persistence.xml. If you want to apply the same handling to your one-to-many associations, you still have to add an @OrderColumn annotation.
Links mentioned in the video:
thorben-jansse...
thorben-jansse...
thorben-jansse...
thorben-jansse...
thorben-jansse...
thorben-jansse...
Like my channel? Subscribe!
➜ bit.ly/2cUsid8
Read the accompanying post: thorben-jansse...
Want to connect with me?
Blog: thorben-jansse...
Twitter: / thjanssen123
Facebook: / thorbenjanssenofficial
Linkedin: / thorbenjanssen
Just use Persism and move on.