spring-utils icon indicating copy to clipboard operation
spring-utils copied to clipboard

Example for wiring up the multi-tenant application context?

Open basejump opened this issue 9 years ago • 9 comments

look like an interesting solution. do you have an example? read the blog post that was posted 2007. also noticed you added multi-tenant support for hibernate 4 but don't really see how that would come into play as this is swaping out the datasource and thus would seem to be redundant if using the architecture that hibernate requests.

basejump avatar May 30 '16 17:05 basejump

The hibernate4 supports integrates the core support (the filter setting a tenant in the ContextHolder) and depending on that set value it will tell hibernate to do something with tenant. That is the integration, you don't need to swap the datasource (depending on your needs). The code predates that support (we initialize used it with early hibernate3 versions and with other code, like JMS).

More recent code is here. I moved it to a separate project a while ago.

mdeinum avatar May 30 '16 18:05 mdeinum

thanks for the update. I see the resolver for hibernate but not the multi_tenant_connection_provider. Did you basically setup the app like this? https://github.com/vtajzich/spring-hibernate4-multitenant/tree/master/mt-core/src/main/resources

basejump avatar May 31 '16 19:05 basejump

The multi_tenant_connection_provider is for you to implement, if you use the setup as you linked to there is no advantage in using that or plain switching as described in the blog post from 2007. When it does become useful is if you have a single database with for instance multiple schemas and you need to to switch the schema. Else I would probably use the switching as described in the blog. Which has the added advantage that if you mix it with a JdbcTemplate you can use both hibernate and JDBC whilst integrating only with hibernate would give you that.

mdeinum avatar Jun 01 '16 05:06 mdeinum

The TargetSource implements is missing in spring-multi-tenancy, why?

blling avatar Apr 29 '20 06:04 blling

It isn't missing those are part of the Spring Framwork itself.

mdeinum avatar Apr 29 '20 09:04 mdeinum

Then which implementation should I use? I didn't know how to use multi talent with your project, is there a complete demo?:-)

blling avatar Apr 29 '20 12:04 blling

Well actually you don't need that. You can use an extension of the AbstractRoutingDataSource from Spring itself, implement the method and return from that TenantContextHolder.getContext().getTenant(). That way you can switch datasources.

mdeinum avatar Apr 29 '20 15:04 mdeinum

But I want to make any bean tenancy, not just datasource :-(

blling avatar Apr 29 '20 16:04 blling

Please send me an email instead of hijacking an issue for a chat on what beans you want to make multi tenancy aware.

mdeinum avatar Apr 29 '20 17:04 mdeinum