简体   繁体   中英

Working with two different Databases with Spring-Data-JPA

I'm working in a project where I'm supposed to read data from a database, called EBS, send it to the front-end and use it alongside other data to persist in another database. Let call it CPP.

The EBS must be read-only. Nothing should be persisted there. And they want all the specific queries to be stored in a xml file. For now, it's stored in the orm.xml.

I tried this solution , but it ended up creating a new table in the EBS and nothing was returned from CPP.

My questions are:

1 - How do a specify those native queries in orm.xml should be run in the EBS datasource? The datasource of CPP is in the application.properties file.

2 - Is it possible to JPA not create table with the @Entity annotation? Every time I use that, JPA ends up creating another table in the EBS. If not, is it possible to map the query directly to a POJO?

I would appreciate a solution based on JpaRepository. Thanks in advance.

There can be multiple persistence-unit in persistence.xml file but the name of those persistence units should be different .

If you don't want the entities to be created automatically then use application-managed entity manager

refter JPA application-managed entity manager

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