简体   繁体   中英

Spring Data JPA repository multi-tenant single schema technique

I'm just getting started on a spring app that is currently using spring data with a jpa repository. I'm planning on the app being a multi-tenant app using a single database schema. What I'm trying to figure out is the best way to attach the tenant id to each query. Of course I can write each query in the repository to expect a tenant id parameter and grab the tenant id out of a thread local or similar, but I was wondering if there was a better technique that is commonly used in this situation? Maybe there is a more declarative way to do it that I haven't come across yet.

You are using Spring JPA over some JPA implementation (Hibernate, EclipseLink, etc.). So, you need to configure multitenancy at JPA provider level. For hibernate - see here

Also you may check alternative way - this (warning: RUSSIAN language inside)

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