-->
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: Composite mutating key
PostPosted: Wed Mar 19, 2008 9:59 am 
Regular
Regular

Joined: Wed Oct 15, 2003 4:40 pm
Posts: 67
Hi,

Both the manual and Hibernate in Action discourages use of composite keys but I'm stuck with a legacy schema that looks simplified like a classic

Order: primary key (customer, ordernumber) and
OrderRow: primary key (customer, ordernumber, rownumber)

and I've mapped them OK as a bidirectional one-to-many, implemented hashCode and equals() etc. The order rows are mapped to a List.

The problem appears when I remove a row from the middle of the list. If I persist, my cascade-delete-orphan pics it up but then I end up with a blank slot in my list on next reload (expected, since I get a gap in the row numbering).

So I try renumbering the rows. Not only is a little unsettling to modifying a primary key like that, it simply doesn't work. If I have 3 rows with row numbers 0, 1 and 2 and remove #1 I see the delete statement for #1 but I don't get any update statement for row#2 -> row#1 (probably due to key equality?)

Am I mapping it wrong? Are there any workarounds?

PS. Being a composite key, I have to do all key management myself, correct?

Thanks in advance,
Nik[/code]


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.