• Post Reply Bookmark Topic Watch Topic
  • New Topic

Comparing two Java Objects. Which is the best way???

 
Mithun Kulkarni
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a requirement in my project to migrate data from one database to another database (a different one). I am planning to build a data comparison tool, which will compare the data between source and destination DB.
I am using JPA implementation of Eclipselink in my application.
I want to know which of the below approaches is better :

Approach 1: Read data from source DB(stored as XML blob) into an object model (contailing entities) and then read data from the destination DB(stored in distributed relational manner) into a new Object model. The compare the two object models. Here I can override equals() in all my entity classes and use Apache commons library to compare the object models.

Approach 2: Read data from the source DB which is an XML, then read data from destination and build an xml out of it. And then compare these 2 xmls and report the differences.

So is there any other better approach to achieve my requirement?
Please help.

Thanks in advance,
MK
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Encode the two BLOBs into Base64 and do the String comparison on those encoded Strings.
 
Mithun Kulkarni
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Freddy Wong wrote:Encode the two BLOBs into Base64 and do the String comparison on those encoded Strings.


Thanks for the reply.
Here the object model is stored as Blob only in source database, where as in destination the object model has a relational data base model. And each entity is saved inn its table.
So I dont think I can directly use this approach.

Thanks,
MK
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks to me like both of your models fall apart if the order of elements does not match the order of destination DB recovery.

Therefore you should hunt for a solution that works no matter what the order of elements.

Looks like you are in for laborious loading of item by item from the first DB, checking if it exists in the second and storing the items which don't exist in some form for a batch update.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!