Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] How to compare entities from two different databases and replace one with the other?

Thanks James for those useful tips; this API has helped me a lot.
 
I think this eclipselink's change set API needs more civerage in the wiki so that other guys can benefit from it.
 
It is also useful for audit logging purposes where just the changes made to the entity, but not the entire entity, needs to be logged.
 
 
By the way, I would like know if there is any way to merge entities based on the object equality instead of the primary key equality;
the reason being that when we compare entities from two data bases, most of the times, the primary keys (pseudo identities, usually numbers for easy mapping of references) will be different where as logically the entities are same based on some unique field(s). 
 
So, we had to selectively compare the unique fields for logical equality and then selectively copy all the fields from one entity of reference database to the other entity of the comparing database, carefully avoiding the copy of primary key. It would be very helpful, if there is any option to ask eclpselink to merge by logical equality rather than primary key equlity.

Can you guys let me know if this is possible with eclipselink?
 
Thanks and Regards,
Samba
 
 
On Wed, Apr 7, 2010 at 5:59 AM, James Sutherland <jamesssss@xxxxxxxxx> wrote:

Assuming the objects have the same primary keys, you could read from one and
call merge() into the other.  This would merge any changes, or do nothing if
no changes.

There is a compareObjects() method on AbstractSession that will compare two
objects and return if they match.

If you get the UnitOfWork after merging you can get the UnitOfWorkChangeSet
that contains the set of changes.

There is also a compareForChange() method on ObjectBuilder that will compare
two objects and build an ObjectChangeSet.

Doing this for an entire database may take a while depending on the database
size.  You may be better off using lower level database utilities, or just
drop the test db, and clone the reference.


saasira wrote:
>
> Hi all,
>
>     I need to compare data in two databases, one a test db and the other
> being reference db, and then patch the differences in the database that is
> being compared from the
>     data in the reference db.
>
>     Can eclipselink detect changes between two entities, each loaded by
> a different entity manager?
>
>     Can I use the eclipselink change tracking api ( merge the comparable
> entity with reference entity manager and then invoke UnitOfWork.
> getUnitOfWorkChangeSet() or
>     UnitOfWork.getCurrentChanges() ) for finding the differences between
> the
> test entity and the reference enitity?
>
>
>    I'm open to any other approach that can help me achieve this; even
> hibernate or openjpa is also ok to me!
>
> Thanks and Regards,
> Samba
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>


-----
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://old.nabble.com/How-to-compare-entities-from-two-different-databases-and-replace-one-with-the-other--tp28094979p28164598.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top