0

I have a scenario where I have a Database with some records in it already. I need to replicate the information in other database , with the datasource information derived in the run time.

The entity model remains the same in both the databases and all I need is to migrate the information from one to another.

Related question I found is this : Two datasources using the same entities/repositories using spring data jpa

Also in the solution there it is mentioned to use a 'AbstractRoutingDataSource' which can derive the information from the tenant.

My use case does not fit there exactly, or I do not know how to fit it in.

My requirement is like

DataSource1 -> EntityManager1 -> Persistence Unit1.
DataSoruce2 -> EntityManager2 -> Persistence Unit2.

Both the persistence unit has the same set of classes.

I need to do

EntityRepo_associated_with_datasource1.find()  
 and then write them to  EntityRepo_associated_with_datasource2.saveAll().

Any pointers on this ?

Community
  • 1
  • 1
Avis
  • 53
  • 1
  • 7

1 Answers1

0

If you want to syncronise 2 databases use the liquibase API do not try and do this with JPA.

You can create a changeset that blows away all the data in the database to by updated, then fills it with data from the replicated set.

Essex Boy
  • 7,565
  • 2
  • 21
  • 24
  • Can we read based on some conditions and replicate only those selected records ? – Avis May 16 '17 at 04:10
  • Yes, it's not simple you will have to override some of the liquibase classes, but I have tried both ways and in my opinion liquibase is by far the easiest. – Essex Boy May 16 '17 at 08:01
  • Is there a actual technical working model for this without using liquibase ? – Avis May 29 '17 at 09:25