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 Mon, 19 May 2008 23:28:54 GMT

  Here is a prototype for migrating data using OpenJPA attached as ~100KB
jar that *must* precede openjpa jars in the classpath. 

  The solution is based on OpenJPA module named 'Slice' which supports a
single EntityManager be connected to multiple databases (or slices) in the
*same* transaction. This notion is extended to create a specialized Slice
configuration which accepts two and only two databases as 'source' and
'target' slices and a specialized StoreManager that directs all read
operation to 'source' slice and write operation to 'target' slice. The
user-visible effect is of migration i.e. whatever data is read *and dirtied*
from the 'source' database is written to the 'target' database. 

  Because of the special nature of configuration, I named this configuration
as 'nomad' and hence the configuration for migration looks like
<persistence-unit name="migrate">
            <property name="openjpa.BrokerFactory" value="nomad"/>
            <property name="openjpa.ConnectionDriverName"
            <property name="openjpa.slice.source.ConnectionURL"
            <property name=""

 Of course, the 'source' and 'target' slice can use different database
drivers etc. as per-slice configuration allows. The only thing to remember
is the slice names are hard coded as 'source' and 'target' and the
specialized BrokerFactory is aliased as 'nomad'.

  The behavior is exemplified by the attached JUnit Testcase. openjpa-nomad.jar persistence.xml  

   Note that this is a quick prototype and whoever plans to play with it
should be ready for exception stack traces.
View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message