SCJP,SCWCD1.3,SCWCD1.4,SCJD,SCBCD5,SCEA5
SCJP, SCJD, SCWCD, OCPJBCD
The entity life cycle comprises the states (see jpa spec 3.2)Both are detached
refresh() can only be applied to managed entities. Otherwise an IllegalArgumentException is thrown.you can reattach it with refresh
According to jpa spec 3.2What distinguishes a New Entity with an existing primary key and a detached entity with the same primary key?
Unfortunately the meaning of "persistent identity" isn't defined in the spec. But in Pro EJB 3 (one of the authors was also leader in the jpa specification) on page 18 it is explained to beA new entity instance has no persistent identity, and is not yet associated with a persistence context
In this sense there is no entity with state "new" whose primary key already exists in the database.An entity has a persistent identity when there exists a representation of it in the data store, that is, a row in the database.
SCJP 5 (98%) - SCBCD 5 (98%)
Originally posted by Mellon Sun:
What distinguishes a New Entity with an existing primary key and a detached entity with the same primary key?
SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
SCJP,SCWCD1.3,SCWCD1.4,SCJD,SCBCD5,SCEA5
SCJP,SCWCD1.3,SCWCD1.4,SCJD,SCBCD5,SCEA5
SCJP,SCWCD1.3,SCWCD1.4,SCJD,SCBCD5,SCEA5
persist(department) takes department into the persistence context.Why after merge, department2 is still detached?
SCJP 5 (98%) - SCBCD 5 (98%)
Generally: If department2 is not contained in the persistence context, then
department2 == em.merge(department2) is false.
SCJP, SCJD, SCWCD, OCPJBCD
please have a look into the specs before posting such wrong statements. JPA spec 3.2.4.1 clearly says:If an entity is not existing in the database then the merge will throw an exception. The merge method must be used for an entity that exist in the database.
The semantics of the merge operation applied to an entity X are as follows: If X is a new entity instance, a new managed entity instance X1 is created and the state of X is copied into the new managed entity instance X1.
SCJP 5 (98%) - SCBCD 5 (98%)
Consider Paul's rocket mass heater. |