I have a list of sub-values for a class in Hibernate. My initial implementation was a Set, but that returns the values in what is essentially 'database order' (likely based on a clustered index, which is almost insertion order).
I looked at switching to List, so I added a , but I quickly ran into a problem with there being nulls in the java Lists that were getting returned. Some of my data is written by Hibernate, but some of it is also written by SQL scripts.
What I'd like is a sortOrder attribute that isn't tied to the position in the list, so that if there are duplicated i.e. { 1, 3, 3, 10 } it is mapped appropriately to { 0, 1, 2, 3} where the order of the 2nd and 3rd item fall back to database order. Nulls are fine also, and I don't care if they get put at the front or back of the list (so long as the behavior is consistent).
I looked at Bag, but I wasn't sure how to get the sortOrder attribute into the definition, and I was a bit worried about it allowing duplicates. I'd still like to have the same constraints as I did when I had Set (I believe the parent/child tuple was always unique).
Suggestions? Can I tweak Bag to make it act as a List with a sortOrder as opposed to a List with an index? What else do I need to do to protect the code from getting hung up by data entered directly by SQL?