Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Multi Tenancy support with hibernate 4
PostPosted: Wed Dec 14, 2011 7:38 am 
Newbie

Joined: Wed Dec 14, 2011 7:32 am
Posts: 2
I am looking to build a muti -tenancy application (shared database shared schema) using hibernate 4.

Hibernate 4 says it supports (http://opensource.atlassian.com/project ... e/HHH-5697). I am not finding any documents or sample example , how to generate tenant wise session or read /write data tenant wise.

Any help or start point will be appreciated.

Thanks...


Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Sun Jan 01, 2012 8:54 am 
Beginner
Beginner

Joined: Thu Jul 31, 2008 8:28 pm
Posts: 24
I'll also be happy to see some getting started documents.

Ido


Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Thu Jan 05, 2012 12:52 pm 
Newbie

Joined: Wed Dec 08, 2004 3:41 pm
Posts: 3
I haven't tried this out myself yet, but the unit test for Multi-Tenancy would be a good place to start:

https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/test/java/org/hibernate/test/multitenancy/schema/SchemaBasedMultiTenancyTest.java


Last edited by kbyrne on Fri Jan 13, 2012 5:21 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Fri Jan 06, 2012 3:09 am 
Beginner
Beginner

Joined: Thu Jul 31, 2008 8:28 pm
Posts: 24
The unit test are good but not enough.

I'm using Hibernate4 as a provider of JPA, how do I use multi-tenancy in this senario?

Thank you,
Ido.


Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Mon Jan 09, 2012 12:19 pm 
Newbie

Joined: Wed Dec 08, 2004 3:41 pm
Posts: 3
It doesn't look like multi-tenancy is possible with JPA out of the box.

Here's the code Hibernate code that implements a JPA EntityManager:

https://github.com/hibernate/hibernate-orm/blob/4.0.0.Final/hibernate-entitymanager/src/main/java/org/hibernate/ejb/EntityManagerImpl.java

It would need some way inject some sort of custom tenant selector class, similar to the way the interceptor is.

In addition a MultiTenantConnectionProvider would needed to be added to the Service Registry, and I haven't found a way to do using JPA.


Last edited by kbyrne on Fri Jan 13, 2012 5:21 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Mon Jan 09, 2012 5:42 pm 
Newbie

Joined: Mon Jan 09, 2012 5:34 pm
Posts: 1
Hi I read your post on multi-tenancy and hibernate. I am from Corent Technology and wanted to let you know that we have a "plug-in" multi-tenancy solution for Hibernate. It makes your application multi-tenant without changes to your code. Check out the website at: www.corenttechnology.com or you can send me an email to laiken@corenttech.com


Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Wed Feb 22, 2012 1:50 pm 
Newbie

Joined: Wed Feb 22, 2012 1:08 pm
Posts: 2
Hello

Indeed following example https://github.com/hibernate/hibernate- ... yTest.java is very useful to get a running multi-tenant application. I am missing an example of how to use CurrentTenantIdentifierResolver though. Does anybody have an
example on how to use it correctly? I tried to do following:

private static CurrentTenantIdentifierResolver currentTenantIdentifierResolver;

...

configuration.setCurrentTenantIdentifierResolver(currentTenantIdentifierResolver);

but that without success.. obviously.

Thanks for any help!
Cheers


Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Thu Feb 23, 2012 12:53 pm 
Newbie

Joined: Wed Dec 08, 2004 3:41 pm
Posts: 3
Take a look at the new 4.1 documentation for Multi-tenancy, there's a mention of CurrentTenantIdentifierResolver there.

http://docs.jboss.org/hibernate/core/4.1/devguide/en-US/html/ch16.html

The only link on the Hibernate Docs page is to the 4.0 version, so I had to mod the url to find 4.1


Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Fri Feb 24, 2012 9:57 am 
Newbie

Joined: Wed Feb 22, 2012 1:08 pm
Posts: 2
Thanks for the reply. actually the only problem is how to use a CurrentTenantIdentifierResolver. That means, i now how to set it up
but not how to use it later. Setup: Create Class which implements CurrentTenantIdentifierResolver and do
cfg.setCurrentTenantIdentifierResolver(..) .

So i have MyCurrentTenantIdentifierResolver but now i am stucked. Should i enhance it with setTenant(..) and later resolve
if it changed.. hm.. it s more a logical problem how to use it generally. I will guess it comes to my mind later.. If someone has any
idea, well i am glad to hear that of course.
Thanks


Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Wed Feb 29, 2012 6:22 am 
Newbie

Joined: Wed Feb 29, 2012 5:55 am
Posts: 6
Your implementation of CurrentTenantIdentifierResolver would need some source to extract the current tenant from. for example you could resolve it by accessing the current session from within the resolver, the userdetails of the authenticated user, using a servlet-filter to manually set the current tenant in each request or similar.

But there seems to be a non-trivial issue regarding the internal usage of the configured CurrentTenantIdenfierResolver: https://forum.hibernate.org/viewtopic.php?f=1&t=1014559. I'm currently stuck at exactly this issue and I don't really like the idea to subclass SessionFactoryImpl. Does anybody have a hint how to solve this in a more elegant way?


Top
 Profile  
 
 Post subject: Re: Multi Tenancy support with hibernate 4
PostPosted: Fri Dec 14, 2012 4:55 pm 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
what is the purpose of the 'any connection' in multi-tenancy provider. I use a database strategy and I have not a clear idea of this connection having no tenant id.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.