Home > Back-end >  In Spring Data JPA using Schema Multi Tenant, how to join with other schema although the same entity
In Spring Data JPA using Schema Multi Tenant, how to join with other schema although the same entity

Time:11-16

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?

CodePudding user response:

That's not possible with JPA.

Btw. JPA doesn't know multitenancy that's a Hibernate feature.

  • Related