0

I have two different (entity1 and entity2) mapped (@OneToOne or @OneToMany) entities from two different database schemas (db1 and db2). If I try traditional ways, I got errors that are about "db1.entity2 does not exist". Because entity1 is in db1 and entity2 is in db2.

I tried to fill all the entity1 objects with entity2 objects after findAll();. But it takes a lot of time (more than 20 sec.)

Is there any way to map them to each other or fill after in a quick way?

Note: I can not get all the entity2 data from the database each time. Because there are a lot. Note 2: I will try to get entity2 objects I need, with Native Query by the list of id.

I use the last version of Spring Boot JPA Projection, MySQL db, and Java 11.

1 Answer 1

0

You can add schema="db1" for entity1, and schema="db2" for entity2 in JPA annotation or xml mapping.

If there are a lot of entity2 for an entity1, declare the relationship as LAZY. You can use JPQL/Criteria API to get certain entity2(s) instead of native query.

Try Cmobilecom JPA that is small, fast and smart in generating SQL.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually, the problem is not that. I already configured the different databases with the schemas. I need something about business logic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.