Hello,
We are noticing some strange behavior with Hibernate's JPA. There is an object called Customer composing a List of PaymentMethod instances with a OneToMany annotation specifying a join column. PaymentMethod is abstract, extended by a CreditCard object using a discriminator.
Now we can add CreditCard instances to a Customer, persist it, remove items from the list, add new CreditCard instances, merge, read the Customer back out and everything ends up like you'd expect.
However, if we read a persisted Customer with a CreditCard out and then completely replace the PaymentMethod list with a new list instance, containing a new CreditCard instance, then call merge we end up with something very odd. The CreditCard instance that was originally persisted with the Customer is still in the database. The new CreditCard instance is also in the database, but does not have a foreign key pointing to Customer. When we read the Customer back out we get the CreditCard instance originally associated with the Customer when it was persisted, which was not associated with the Customer object when it was merged. Since the FK on the new CreditCard instance is null, we never see that one associated with the Customer again after the merge.
Unfortunately, this is done across a web service. After the marshalling/unmarshalling at each side, the list of PaymentMethods is always new.
We have been able to duplicate this behavior without ser/deser across the wire, using only Hibernate and Spring DAOs.
Please advise, and thank you.
--
Tim
|