Hi, Looking for some insight.
I have a OneToMany mapping like this:
Code:
<list name="addresses" cascade="all-delete-orphan" where"HIDDEN='Y"" >
<key column="PERSON_ID" not-null="true" />
<list-index column="SORTORDER" />
<one-to-many class="something.Address"/>
etc
Everthing works well except when a "logical" delete occurs (the HIDDEN column is set to 'Y'). I filter the collection
at fetch time using the where clause. In this way, I am only working with addresses that are not "deleted". I dont want to physically delete for historic purposes.
The problem is really with spring MVC not being able to post back beacause of the SortOrder (index) not aligning, but I want to fix this problem upstream.
Example:
If a person has 5 addresses and one of them (the 3rd) was "deleted" using HIDDEN = 'Y' then Hiberante will return 4 addresses (perfect),
but the 4 records will have a gap in the actual collection
Code:
DB:
ADDRESS_ID PERSON_ID SORTORDER HIDDEN
5 45 0 N
6 45 1 N
7 45 2 Y
8 45 3 N
9 45 4 N
The created Java List
ADDRESS PERSON SORTORDER HIDDEN
5 45 0 N
6 45 1 N
8 45 3 N
9 45 4 N
3rd item is missing, and the sortOrder has a gap and Spring does not like that apparently.
Does anyone have any ideas how to manage this? Is there a way I can force a recalculate of the sortOrder when an item is set to HIDDEN=Y
so that HIDDEN=Y are at the bottom of the list therefore when the collection is fetched using the where clause the sortOrder is still intsact.
Hope this makes sense. I dont want to throw code at this if I dont have to.
Thanks
-J