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]
|