Hibernate version:
Annotations: Version: 3.2.0 CR1
Core: version 3.2 cr2
EntityManager: Version: 3.2.0.CR1
Hi,
I have Cascade Persist set on both sides of a relationship between Person and Address.
I create a relationship between a persistent Person which is attached and a transient Address which is not attached. The Address is inserted in the Database and the relationship is created.
Code:
person.setHomeAddress(address);
System.out.println("em.contains(address)" + em.contains(address));
em.getTransaction().begin();
em.getTransaction().commit();
System.out.println("em.contains(address)" + em.contains(address));
Before the commit, the person is attached and the address is detached. During the commit, the address is persisted. After the commit the address is attached.
This is confusing me because a persist is cascaded to the Address even though I never invoke persist on the address.
When I remove the cascade persist option, the address is not persisted.
Can someone explain how persist is cascaded in situations where persist() is not explictly called?
Thanks