-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Suggestion for simple feature for lists (and maps)...
PostPosted: Sat Jul 02, 2005 1:27 pm 
Newbie

Joined: Wed Jun 15, 2005 4:58 am
Posts: 6
Hibernate version: 3.0.5

Hibernate does a wonderfull job of managing index columns of a list. One possible issue, however, is that the database 'unique' constraint is not used to enforce the sort order (while logically, it is certainly unique within a particular list). So far (in my experience),

I have never experienced problems with Hibernate's managing of the index column. However, it feels safer (to me) to let database enforce data integrity (in this case, list uniqueness).

A dumb solution would be to add the list-index column to the child element with 'insert="false"' and 'update="false"' and add a 'unique-key' attribute to it (along with whatever happens to be "natural parent definition" - probably 'many-to-one' part). The problem is that the reordering update fails since at some point in the middle of the update two rows have the same list index.

A possible correct solution would be to have hibernate manage that relationship (instead of a hack above). Then during the update, the duplicates can be prevented by setting one of the values to an "invalid value" (e.g. -1) temporarily - and then setting it to the correct new value. For example:

Code:
step 1:
   item 'x', index="0"
   item 'y', index="1"

step 2:
   item 'x', index="-1"
   item 'y', index="0"

step 3:
   item 'x', index="1"
   item 'y', index="0"


This, of course, might have performance implications - so perhaps this behavior (and unique constraint) should be selectable.

For example, list definition might look like this:

Code:
<list name="children">
   <key column="parent_id">
   <list-index column=indexcolumn" ENFORCE-UNIQUE="true"/>
   <one-to-many class="Child"/>
</list>


The same sort of thing can apply to maps to enforce uniqueness of the 'map-key'.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.