This represents the structure I have not the data or tables.
Hibernate version: 3.0
Mapping documents:
Object A map:
Code:
<id name="shelfId" column="shelf_id"
<generator class="native"/>
</id>
....
<bag name="bookInfo" table="books" inverse="false" cascade="save-update">
<key column="shelf_id"/>
<one-to-many class="BookInfo"/>
</bag>
Object B map:
Code:
...
<composite-id>
<key-property name="shelfId" column="shelf_id" />
<key-property name="bookId" column="book_id"/>
</composite-id>
<version name="version" column="version" unsaved-value="null"/>
...
Object A object:
Code:
...
private Long shelfId;
private ArrayList objB
...
Object B object:
Code:
...
private Long shelfId;
private Long bookId;
...
In my application I can modify the list of object B items contained by object A including adding and removing elements to/from the list. After the elements in the arraylist have been modified to satisfaction, the user is able to persist their changes to the database.
If the user deletes an element from the ArrayList, I call the remove method on the array list removing the element from the list and place the object in another list that is used to actually delete the object from the database. All of this seems to work fine EXCEPT when object B has a complex id as above.
Adding elements to B and calling save on object A works fine with the complex id.
When the user chooses to delete an element, I remove the object from the arraylist and build my delete list of objects to be deleted from the database. When it is time to save the data to the database I do the following:
Code:
objectA.saveOrUpdate();
This fails if I have removed objects from the arraylist of object B.
I do have a hashCode and equals methods in object B.
I do this same thing on other objects that do not have a complex id and everything works fine. Unfortunately I do not have the luxury of modifying the database to do away with the complex id.
Any ideas?