-->
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.  [ 9 posts ] 
Author Message
 Post subject: Different customers in one database?
PostPosted: Mon May 24, 2004 9:59 am 
Newbie

Joined: Mon May 24, 2004 9:37 am
Posts: 2
Hi,
while playing around with hibernate and some webframeworks a very basic question arised to me:

Suppose you have a webapplication which supports an great number of customers (let's say up to 200).
The application uses 50 "domain" tables (tables which store customer data) in the backend. All the access and the OR mapping is made via hibernate.

The question is, what might be the best way to organize these tables?

1.) Create a database per customer with all tables in it.
Pros: Very easy to manage, all customers are seperated.
Small tablesizes.
Cons: Connection pools need to be build for every database.
200 customers x 10 connections = 2000 pooled connections?!?

2.) Create one database with all tables in it and link their entries against a customer table.
Pros: One connectionpool for all customers
Cons: Every query needs to link with the customer table.
Customer data is only seperated by logic.

In the moment I would strongly prefer 2.) because of the connectionpool size. What is the best for hibernate (concerning 2nd level cache etc).
Do you have any additional thoughts on it?

Greetings,
Markus


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 10:02 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
A trivial solution would be to use a NamingStrategy and prefix the table names for each customer. You can then assign a NamingStrategy on a per Hibernate SessionFactory basis. Hm, I guess it doesn't solve all of your problems, but its probably worth thinking about.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 24, 2004 1:21 pm 
Newbie

Joined: Fri May 07, 2004 2:46 pm
Posts: 5
This is a very common problem. If you are using Oracle, you can use the Virtual Private Database feature to automate option #2 for you. It will look like you are using private tables, but they will actually be implemented as single tables, and the database will silently append conditions to each query to specify the customer.

See http://otn.oracle.com/oramag/oracle/04-mar/o24tech_security.html

-eric


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 25, 2004 5:58 am 
Newbie

Joined: Fri Aug 29, 2003 5:12 am
Posts: 2
I have worked for some ASP, they always choose your first choice for security reasons (even if they have thousand of customers) : we all make mistakes (programmer, admin), in a ASP context consequences can be dramatic.

Virtual Private Database from Oracle is a nice choise.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 25, 2004 5:10 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 3:09 pm
Posts: 58
Another possibility that may work (if all databases are on the same server) is to change to the right database using connection.setCatalog(). I think this may cause problems with second-level caching though...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 8:28 am 
Newbie

Joined: Mon May 24, 2004 9:37 am
Posts: 2
hm. looks like there is no easy solution to this problem.
I would realy prefer to keep the data seperated.

Instead of using oracle I would prefer a solution which is as database independent as possible.

Would it be possible to extend the Sessionfactory to accept multiple Datasources and deliver Sessions(with different DataSources) based on a parameter?

E.g. user A gets a session which points to database A and
user B gets a session which points to database B?

The rest would be totally transparent to the application.
Would this affect the second level cache?
I would love to have it in place for the application.


thanks for all your proposals,
Markus


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 8:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is not possible. You can however create one SessionFactory per User.


Top
 Profile  
 
 Post subject: Different customers in one database?
PostPosted: Sat May 03, 2008 5:20 am 
Newbie

Joined: Tue Apr 29, 2008 9:15 am
Posts: 4
jfifield wrote:
Another possibility that may work (if all databases are on the same server) is to change to the right database using connection.setCatalog(). I think this may cause problems with second-level caching though...



If we are disabling the second level cache will it work????


Thanks & Regards

unnis


Top
 Profile  
 
 Post subject: suggestions
PostPosted: Sun May 04, 2008 4:20 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Hi,
Let security implementations deal with security considerations. In an ideal world, there would be a security standard for db-access. There isn't one. Therefore, I see 2 options for you:

1. Design your model with tables shared between customers, and rely on specific database security impl to support your needs, like the mentioned Oracle impl. Security-aware customers will understand why this dependency on Oracle is needed. This means more integration work and less development for your project.

2. Design a security model into your application. For example, M:N access control table, telling which user may access which resource. As you said, this means that security is implemented at app-level and not db-level. This means more development and less integration work for your project.

Since I don't know your project's requirement, I would at least invest some time researching and estimating the effort for both approaches, and then decide.


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