About Question enthuware.oce-jpad.v6.2.443 :

Moderator: admin

Post Reply
M_Z

About Question enthuware.oce-jpad.v6.2.443 :

Post by M_Z »

The explanation is not completely correct, this already was discussed here: viewtopic.php?f=4&t=950

In case of "orphanRemoval=true" the "remove" is not necessary, just commit of transaction will remove the Address:

Code: Select all

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>

admin
Site Admin
Posts: 10058
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.443 :

Post by admin »

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.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

jszczepankiewicz

Re: About Question enthuware.oce-jpad.v6.2.443 :

Post by jszczepankiewicz »

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.

admin
Site Admin
Posts: 10058
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-jpad.v6.2.443 :

Post by admin »

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.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 62 guests