I have a requirement for my Customer object to contain an ordered collection of Script child objects, and to be able to display these in in table with move up and move down functionality.
My first thought was to store these in a List and use Hibernate's @IndexColumn. However, I'm not sure what would happen if 2 users fetch the data and then both create a new Script. Won't the 2nd user to save get an exception because Hibernate will try to assign the a duplicate value to the index column of this second object (i.e. it will be the same as the first objects and the database will disallow the CREATE because of unique constraint)?
Am I correct in my thinking?
As an alternative, I could just use a ordered Set and manually manage the index column. Is this a better solution? If so, I assume I would need to override the EntityHome.persist method in my ScriptHome, and in this method add a query to select the max(index) and then assign this value + 1 to my Script's index property.