When the entity manager is used to merge two newly created objects of type 'Customer' with different 'Addresses', Hibernate performs two inserts and an additional update that leads to the addresses being equal. Customer is a very simple @Entity that holds a reference to Address, which is @Embeddable. Address is also very simple and only holds a single String (the 'city'). The additional update probably occurs because in the default constructor of Customer the Address is set to a default static constant value. The additional update does not occur if EntityManager#persist is used instead of EntityManager#merge or when after the first merge the transaction is flushed and cleared. See the three tests in the attached test case. |