aspose file tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Entity Manager Remove Operation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Storm Applied this week in the Other Open Source APIs forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Entity Manager Remove Operation" Watch "Entity Manager Remove Operation" New topic
Author

Entity Manager Remove Operation

Khaled Mahmoud
Ranch Hand

Joined: Jul 15, 2006
Posts: 361
Hi all,

According to the EntityManager interface documentation, the remove operation will throw an exception if the passed entity reference is a detached entity.


@throws IllegalArgumentException if not an entity
* or if a detached entity

public void remove(Object entity);


The find and getReference methods will return a detatched entity, also mentioned in the EntityManager documentaion if invoked in a transaction scoped entity manager.

My question is Can I remove an entity using the remove method in a transaction scoped entity manager.

Thanks in advance.


SCJP, SCJD,SCWCD,SCDJWS,SCEA 5 MCP-C#, MCP-ASP.NET - http://www.khaledinho.com/
Life is the biggest school
Mirko Bonasorte
Ranch Hand

Joined: May 14, 2007
Posts: 244
Hi,

I'm not skilled at all about scbcd5, but it seems to me that the paragraph of the specification speaks about the requirement to invoke getReference/find inside a transaction: you are not required to call find/getReference inside a transaction, and, in case of transaction-type persistence context, out of a transaction all the objects are detached.

Hope this helps...


SCJP<br />SCWCD 1.4 Upgrade (Remember: me stupid)<br />SCWCD 1.4<br /><a href="http://jcp.org/aboutJava/communityprocess/final/jsr220/index.html" target="_blank" rel="nofollow">SCBCD 5.0</a><br /><a href="http://www.enthuware.com" target="_blank" rel="nofollow">SCBCD 5.0 mock exam</a> <br /> <br />SCEA 5 Part1: Preparing...
Khaled Mahmoud
Ranch Hand

Joined: Jul 15, 2006
Posts: 361
Hi,
I think what is meant by "The resulting entity will be detached"
is when the transaction ends. But during the transaction, the
returned entity reference is still managed.
 
Consider Paul's rocket mass heater.
 
subject: Entity Manager Remove Operation