openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Pinaki Poddar <>
Subject Re: Synchronizing two databases with the same model
Date Wed, 07 May 2008 22:36:37 GMT

Hi Jonas,
  Just finished a prototype that specializes Slice to migrate selected
instances from one database to another. But I am not planning to commit it
to trunk right now (mainly because the trick that made it work will require
a single line but dangerous change in OpenJPA :) -- if you are interested I
can send you a small jar (~20KB) that you can play with and give us some
feedback on feasibility of this approach. 

  Additional information on Slice is available at [1][2][3] and also is
documented on SVN trunk. 


Jonas Petersen wrote:
> Hi Pinaki,
> thank you, this sounds interesting. The Slice Plig-In looks quite 
> promising, I'm definitely interested in learning more about this.
> Jonas
> Pinaki Poddar schrieb:
>> Hi,
>>> The most obvious approach would be: fetch objects from datastore A (and 
>>> possibly detach the objects) and then merge them in database B. But this 
>>> rises a couple of problems due to versioning / sequence generators / 
>>> optimistic locking / ...
>>   Another alternative approach is to consider is a single StoreManager
>> with
>> two database connections: one is 'read' connection to 'source' database
>> and
>> the other is 'write' connection to 'target' database. The JPA
>> EntityManager
>> interface remains intact but, below the hood, all 'read' operations
>> happen
>> on 'source' database while any modification is written to target
>> database. 
>>   I prefer this approach because then all the instances are managed by
>> the
>> same persistence context; rather than being realized in one context,
>> detached and then merged onto another. Also the 'migration application'
>> becomes simple. One can issue a query, dirty all the selected instance
>> and
>> then commit. The effect will be migrating all the selected objects from
>> the
>> 'source' database to 'target' database.
>>   Now OpenJPA Slice module already has some support to handle multiple
>> databases in a same persistence context. I tweaked Slice a bit to get the
>> 'migration' feature as described above.  
>>   If you are interested to explore this further, let me know.

View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message