spring-projects / spring-data-examples

Spring Data Example Projects
Apache License 2.0
5.17k stars 3.39k forks source link

Add Example for Multi Tenancy using Parent-Child relationship #676

Closed bashayam30 closed 8 months ago

bashayam30 commented 9 months ago

I am trying to implement multi tenancy by following the post - https://spring.io/blog/2022/07/31/how-to-integrate-hibernates-multitenant-feature-with-spring-data-jpa-in-a-spring-boot-application

But while using parent child relationship with @OneToMany relation and LAZY fetch, tenantId filter is not applied by hibernate to the SQL JOIN queries to fetch the child records.

Need an example on how to apply tenantId filter for Partitioned Data approach.

Thanks in advance!

schauder commented 8 months ago

Multitenancy is implemented by Hibernate. Spring (Data) just provides some integration for that. What you describe seems therefore to be a problem with Hibernate. Please open an issue with the Hibernate team when you think this is a bug or if you think it should work and you just need help with this you may ask on Stackoverflow, I guess.