1

I am using JPA 2.0 standard and hibernate as the persistence provider. While working with ElementCollections I am curious to know why aren't org.hibernate.collection.PersistentSet updatable?

The method isRowUpdatePossible() in PersistentSet returns false. When compared with PersistentList which are updatable, Set executes multiple deletes and inserts instead of just an update.

For e.g. Consider my entity having a Set which currently has values {1, 2, 3}. I update the set by clearing it and then adding {4, 5, 6}. On calling entityManager.merge(entity) 3 delete and insert queries are fired.

If in the above example I use a List then just one update query is fired with bind values.

The number of queries drive me to a conclusion to use a List when my database can manage to avoid duplicates in the column.

To summarize the questions

  1. Why aren't org.hibernate.collection.PersistentSet updatable? The method isRowUpdatePossible() in PersistentSet returns false.
  2. Is List better then Set when database can take care of duplicates?

Thoughts on these questions would be appreciated.

Andy Dufresne
  • 6,022
  • 7
  • 63
  • 113
  • I don't get it, if you are using JPA why do you have vendor specific features like the persistent set and list that you mention? Can't you do the work with plain JPA? – Edwin Dalorzo Apr 10 '11 at 12:23
  • I think you misunderstood my question. My point was concerned with performance. Why are set not updatable and should List be preferred over set? – Andy Dufresne Apr 22 '11 at 05:48

0 Answers0