Hi all,
In preparation for "SUN Certified Business Component Developer" I am now reading the JPA specification.
I have the following question :
Chapter 3 of the specification, page 49 specifies the effect of the remove operation on entities.
A managed entity instance becomes removed by invoking the remove method on it or by cascading the
remove operation.
The semantics of the remove operation, applied to an entity X are as follows:
1-� If X is a new entity, it is ignored by the remove operation. However, the remove operation is
cascaded to entities referenced by X, if the relationship from X to these other entities is annotated
with the cascade=REMOVE or cascade=ALL annotation element value.
2-� If X is a managed entity, the remove operation causes it to become removed. The remove operation
is cascaded to entities referenced by X, if the relationships from X to these other entities
is annotated with the cascade=REMOVE or cascade=ALL annotation element value.
3-� If X is a detached entity, an IllegalArgumentException will be thrown by the remove
operation (or the transaction commit will fail).
First Question : Point states that if X is a new entity then, referenced entities will be removed too. In the database is there still no relation between referenced entities and X. How the remove operation will be executed ??
Second Question : Does the "cascade remove" mentioned in point two also applies to many-to-many relations.
Third Question : For point three, it is mentioned that if I get a reference to an entity using the EntityManager.find method, the resulting entity will dettatched. How can call The merge or refresh method on a entity,both methods requires that the passed entities to managed.
The find and getReference methods are not required to be invoked within a transaction context. If
an entity manager with transaction-scoped persistence context is in use, the resulting entities will be
detached; if an entity manager with an extended persistence context is used, they will be managed. See
section 3.3 for entity manager use outside a transaction
Thanks in advance
[ October 07, 2007: Message edited by: Khaled Mahmoud ]
[ October 07, 2007: Message edited by: Khaled Mahmoud ]