• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Question about entity operations in the JPA Specification

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic