简体   繁体   中英

JPA: multiple datasource sharing entities?

I have four databases, each having a "customer" table, in fact they are part of an old php application that uses multiple dbs, it test the db existence to activate modules, so if there's a db named "customercare" it displays the correct interface and use the tables form this db.

With JPA, is there a way to mimic this behavior? I mean, having a Customer entity shared across multiple databases?

I've searched across the internet but I've only found partial examples that connect dinamically to differents db on application startup, no examples using multiple datasources at the same time nor sharing entites between datasources.

There is a good article on Spring IO that discusses how to use an AbstractRoutingDataSource to pull in from multiple DataSources. Hopefully this points you in the right direction.

http://spring.io/blog/2007/01/23/dynamic-datasource-routing/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM