Issue
I am using schema-based multitenancy in Spring Data JPA.
properties.put("hibernate.multiTenancy", MultiTenancyStrategy.SCHEMA);
The table structure of the "Common" schema and the "A" schema is the same.
These two schemas are multi-tenant structures that use the same entity.
There's an entry called User in "A" schema and "Common" schema.
How do I join these two entities?
I want to create a query like this. (The schema is currently selected as A by Tenant setting.)
select u.* from user u left join common.user u2 on u.common_id = u2.id;
@Entity
public class Entity {
@Id
private Long id;
private Long commonId; // right?
}
Should I use native query without using JPQL?
Solution
That's not possible with JPA.
Btw. JPA doesn't know multitenancy that's a Hibernate feature.
Answered By - Simon Martinelli
Answer Checked By - Senaida (JavaFixing Volunteer)