Page 1 of 1

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

Posted: Tue Sep 08, 2015 5:32 pm
by romsky
I am confused with third option.

[Option] The customer with primary key matching custID has become detached.
[Explanation] In this case, the customer will become managed again.

That is wrong. If the entity is detached, only the calling persist() can make it managed again.
The calling find() will return null.

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

Posted: Tue Sep 08, 2015 7:53 pm
by admin
Why do you think so?
find cannot return null if a row exists in the database.

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

Posted: Wed Sep 09, 2015 5:22 am
by romsky
admin wrote:Why do you think so?
find cannot return null if a row exists in the database.
Can it be that the entity is removed from database(during commit of pre transaction) and it then stays as detached in EM? Calling find() on such EM will return null or not ?

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

Posted: Wed Sep 09, 2015 9:29 pm
by admin
Yes, but deletion is not the only cause for detachment. You could just detach an entity from the entity manager by calling em.detach(entityRef) also.
So just because an entity is detached doesn't necessarily mean that find will return null.

HTH,
Paul.