This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Section 3.2.1 of EJB 3.0 Persistence Specs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Section 3.2.1 of EJB 3.0 Persistence Specs" Watch "Section 3.2.1 of EJB 3.0 Persistence Specs" New topic
Author

Section 3.2.1 of EJB 3.0 Persistence Specs

Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Hi,

Got a question.
Hope anyone can help me.

Under Section 3.2.1 (Persisting an Entity Instance) of EJB 3.0 Persistence Specs, it says

"If X is a detached object, the EntityExistsException may be thrown when the persist
operation is invoked, or the EntityExistsException or another PersistenceException
may be thrown at flush or commit time."


My understanding is that the "persist" method is for persisting a detached entity.
Why then will the "EntityExistsException" be thrown?

Please help!
Thanks!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

My understanding is that the "persist" method is for persisting a detached entity.
Why then will the "EntityExistsException" be thrown?

Wouldn't you use "merge" instead ?


[My Blog]
All roads lead to JavaRanch
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Hi Christophe,

Yes, to save a detached entity, a "merge" can be used.

But Section 3.2.1 is for the "persist" operation.
It gives the semantics of the operation when performed with a new, preexisting managed, removed and detached entity.

Why is a "detached" entity considered differently from a "new" entity?

Thanks!
Meng Tan
Ranch Hand

Joined: Jan 20, 2001
Posts: 115
Sorry, I have missed the definitions of "new" and "detached" entities early in section 3.2.

A detached entity represents a record that is already in the database but the entity object itself is not associated with any persistence context.

Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Section 3.2.1 of EJB 3.0 Persistence Specs