-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: MULTI-TENANT DATA ARCHITECTURE WITH HIBERNATE
PostPosted: Mon Oct 08, 2007 9:35 am 
Newbie

Joined: Thu Jul 29, 2004 8:31 am
Posts: 7
Location: Brazil
There are basically three approaches to managing Muti-Tenant Data based on the isolation level needed:
- Separated Databases
- Separated Schemas
- Shared Schema

The decision about using one of these 3 approaches is based on the expected number of tenants, database sizer per tenant, number of user per tenant, value-added services per tenant.

I´ve been searching for ways to implement theses architectures using Hibernate but I just find out a reasonable way for implementing the shared schema approach (the use of hibernate filters).

Do anyone knows a efficient alternative for Separeted Databases/Schemas isolation level?

PS: Alternatives I found while browsing the Internet:
Override the getConnection() method of the DataSource to change de Schema.
Problems: 2nd Level Cache

Using Multiple SessionFactories.
Problems: Memory

_________________
Daniel Brasil
CEO Hive.log


Top
 Profile  
 
 Post subject: Separated Databases Multi-tenant Implementation
PostPosted: Mon Jan 21, 2008 9:43 am 
Newbie

Joined: Thu Jul 29, 2004 8:31 am
Posts: 7
Location: Brazil
I'm posting a reply to my own question. I've successfully implemented a Separated Databases Multi-tenant approach with a ConnectionProvider that provides hibernate with the adequate connection based on a ThreadLocal variable especifying the tenant.

Code:
package com.hivelog.logistiks.persistence.infra.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

import com.hivelog.logistiks.persistence.multitenant.ConnectionManager;
import com.hivelog.logistiks.persistence.multitenant.PrincipalManager;

public class ConnectionProvider implements
        org.hibernate.connection.ConnectionProvider {

    public void close() {}

    public void closeConnection(Connection con) throws SQLException {
        con.close();
    }

    public void configure(Properties arg0) {}

    public Connection getConnection() throws SQLException {
        return ConnectionManager.getConnectionManager().getDataSource(
                PrincipalManager.getPrincipalManager().getTenant())
                .getConnection();
    }

    public boolean supportsAggressiveRelease() {
        return false;
    }

}



_________________
Daniel Brasil
CEO Hive.log


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 15, 2008 10:57 am 
Newbie

Joined: Tue Mar 02, 2004 2:22 am
Posts: 5
Daniel, thanks for sharing your solution. A couple of questions:
- Does it solve the 2nd Level Cache problem?
- Have you tried to use it w/ SpringFramework/LocalSessionFactoryBean?


Top
 Profile  
 
 Post subject: Re: MULTI-TENANT DATA ARCHITECTURE WITH HIBERNATE
PostPosted: Sun Nov 01, 2009 1:55 am 
Newbie

Joined: Sun Oct 11, 2009 2:43 am
Posts: 7
Hi,

Can you provide more information on it,because we are going to implement MULTI-TENANT DATA ARCHITECTURE in our system.


Please reply soon!


Top
 Profile  
 
 Post subject: Re: MULTI-TENANT DATA ARCHITECTURE WITH HIBERNATE
PostPosted: Tue Oct 25, 2011 7:45 am 
Newbie

Joined: Thu Oct 06, 2011 5:54 pm
Posts: 6
This create a new connection on database?
This use memory too.
I'm wrong?


Top
 Profile  
 
 Post subject: Re: MULTI-TENANT DATA ARCHITECTURE WITH HIBERNATE
PostPosted: Tue Nov 15, 2011 9:20 am 
Newbie

Joined: Tue Nov 15, 2011 9:13 am
Posts: 1
this is really very helpful to me, specially this part of the article "PS: Alternatives I found while browsing the Internet:
Override the getConnection() method of the DataSource to change de Schema.
Problems: 2nd Level Cache " after having a background check, I found out this is quite helpful. More power


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.