Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Merged entity question

Merge does not know what you changed in the clone, so must merge everything.

If yes access the EclipseLink UnitOfWork from the EntityManager there are
more merge options (shallow, deep), but if you wish to pick and choose what
you merge, you are probably better off doing a manual merge of your objects
in your own code.  A merge that takes an original state object may be
useful, you might want to log an enhancement request for this.  One advanced
mechanism to do this might be to set the object's fetchGroup.


bea-5 wrote:
> 
> Hi,
> 
> I'm using eclipselink with JPA in order to manage some entities.
> Right now I've one entity called Operator with an attribute called
> Contacts, that is a relation-ship one-to-many to other table, with a
> cascade type ALL.
> 
> Some times I update the Operator and the nested Contacts with the
> merge method. I've one question:
> 
> If I've an entity of the database persisted, and I've a new entity
> with the same ID than the one persisted but some data modified, could
> I merge the second entity with the first one with a simple merge
> method? If I do that all the old data not represented in the new
> entity is removed.
> 
> For example, imagine that newEntity is a new entity not managed but
> with an id attribute existing in DB. If I type:
> 
> Operator entity = em.merge(newEntity);
> 
> entity has the values of newEntity. I'd like a mix between both
> entities: the previous persisted and the new values from the new
> entity.
> 
> Thanks.
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/Merged-entity-question-tp25277107p25278123.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top