Person p = (Person) em.find(Person.class, 1); //find the person with address
Address a = p.getAddress(); //an Address entity also exists for this person
p.setAddress(null);
// NOT NEEDED a.setPerson(null);
// NOT NEEDED em.remove(p);
<commit at some time>
There is a little difference between both the questions. In the explanation given in this question, situation 2 is talking about the case when orphanRemoval=true is NOT present and so once you remove the link from person to address, and if you then remove person, address will not be deleted.
In the other question, orphanRemoval=true is the right option.
Not sure but the code is probably not complete:
there is no @OneToOne annotation on address and Address is not Serializable
so correct me if I'm wrong but according to some other questions in this quiz bank this is not correct mapping and at least will generate JPA vendor warning.
It is explicitly given in the question that there is a unidirectional one to one mapping between the two. So even if there is no annotation, it can be safely assumed that this information is present in the deployment descriptor.
Yes, an entity should implement Serializable. But it is a standard practice to ignore it even in the real exam.