Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for wiring up the multi-tenant application context? #2

Open
basejump opened this issue May 30, 2016 · 9 comments
Open

Example for wiring up the multi-tenant application context? #2

basejump opened this issue May 30, 2016 · 9 comments

Comments

@basejump
Copy link

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.

@mdeinum
Copy link
Owner

mdeinum commented May 30, 2016

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.

@basejump
Copy link
Author

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

@mdeinum
Copy link
Owner

mdeinum commented Jun 1, 2016

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.

@blling
Copy link

blling commented Apr 29, 2020

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

@mdeinum
Copy link
Owner

mdeinum commented Apr 29, 2020

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

@blling
Copy link

blling commented Apr 29, 2020

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

@mdeinum
Copy link
Owner

mdeinum commented Apr 29, 2020

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.

@blling
Copy link

blling commented Apr 29, 2020

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

@mdeinum
Copy link
Owner

mdeinum commented Apr 29, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants