[java] Hibernate: How to fix "identifier of an instance altered from X to Y"?

I solve this by instancing a new instance of depending Object. For an example

instanceA.setInstanceB(new InstanceB());
instanceA.setInstanceB(YOUR NEW VALUE);