1

Am using Mysql database and hibernate in JPA. I have two mysql databases in my project. I want to configure these two databases in configuration class of spring JPA. Already I have configured for one datasource using jpa transaction manager bean. I want to add one more datasource to configure. Please consider below scenario.

Mysql Database db1 -Table 1, Table2, Table3

Mysql Database db2 -Table1, Table2

I want to add jpa configuration for above two sql database. Different connections. Whenever repository interface calls for the particular entity, that database should be get called. Please help anyone on this. Thanks in advance.

Santhosh
  • 21
  • 1
  • 5
  • What is the use case? Dev vs Production or both on Production used simultaneously? – Prav Nov 03 '17 at 22:02
  • No both database are in same environment. For example I have the database structute as below mentioned. In Mysql command prompt, after login. #show databases; # database-1, database-2; #use database-1; show tables; # tab1, tab2, tab3. #use database-2; #show tables; # table1,table2; – Santhosh Nov 04 '17 at 06:34
  • I haven't tried this before, but this looks like what you're looking for. [How to use 2 or more databases with spring](https://stackoverflow.com/questions/30362546/how-to-use-2-or-more-databases-with-spring). – Prav Nov 04 '17 at 11:44
  • Am using not two different database like sql, postgre. Am using two databases in my sql. Named DB1 and DB2 – Santhosh Nov 04 '17 at 11:55
  • Ok, in your case you just have `application.properties` with two connections going to the same server with two `spring.ds_items.url` pointing to different databases. `spring.ds_items.url=jdbc:mysql://srv0/db1` and `spring.ds_items.url=jdbc:mysql://srv0/db2` – Prav Nov 04 '17 at 11:59
  • I need java configuration for jpa for the one mentioned above like. – Santhosh Nov 04 '17 at 12:42
  • This person has done it but he's using multiple config approaches for this. https://github.com/spring-projects/spring-data-examples/tree/master/jpa/multiple-datasources – Prav Nov 04 '17 at 12:59
  • Thanks lot parveen. Hope this will be helpful because i had thr same scenario. Thanks let me check and update. Thanks lot. – Santhosh Nov 04 '17 at 16:06
  • 1
    Thanks lot.. as per praveen's link github it was working for me. – Santhosh Nov 12 '17 at 17:41

0 Answers0