mdeinum / spring-utils

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example for wiring up the multi-tenant application context?

basejump opened this issue · 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.

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.

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

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.

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

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

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

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.

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

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