-->
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.  [ 10 posts ] 
Author Message
 Post subject: Hibernate 3.0 and Multiple Databases/Catalogs?
PostPosted: Wed Dec 29, 2004 10:58 am 
Newbie

Joined: Mon Feb 02, 2004 8:27 pm
Posts: 17
Hi there, Can this be done in Hibernate 3.0?

When a user queries or updates the data on our web based application, the first thing that happens is we determine which "catalog" they should affect. We create a new catalog for each user for data protection reasons. (each "user" catalog will typically have around 30 tables with between tens of thousands and millions of rows depending on their usage)

Previously, this would have meant creating XML mapping descriptors for each catalog which, when you have over 2000 is not practical, nor is it practical to write a single web application for such a solution.

We eventually created our own XML data access generator that allows us to include, as one of the arguments, the catalog name so for instance we may have a static method :

addressDAO.findAddress(String catalog, long addressID) ...

We also have classes with non-static methods where the finder class has a method "setCatalog" that must be called before any finder methods are called. The main reason for having both methods was experimentation..

So my question is... can this be automated effectively in Hibernate 3.0? I appreciate that the fact that our schema inherently has tables with identical primary keys across catalogs could cause issues if this catalog approach is not at the heart of much of Hibernate..

Any help would be appreciated!!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Why don't you just set hibernate.default_schema or hibernate.default_catalog before creating your SessionFactory?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 1:26 pm 
Newbie

Joined: Mon Feb 02, 2004 8:27 pm
Posts: 17
We could do that, but we'd then need one session factory per user which means 2000 session factories.. The ideal situation seems to be to have a single session factory..

Wouldn't this solution, in a multi-threaded webapp environment, also mean I would really have to build a new session factory for each new request? (As the request could be coming from any of our users)

I'm sure I could cache them.. but again, having 2000 (and climbing, daily) session factories cached doesn't sound ideal...

We also need to be able to access data across certain user databases sometimes - this happens when two or more of our users are affiliated in some way...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 1:40 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I'm not sure your usage of catalogs is good.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 1:55 pm 
Newbie

Joined: Mon Feb 02, 2004 8:27 pm
Posts: 17
The design of the database isn't really the issue at hand (and way beyond my current remit to change).. it turns out it's a little unusual although I do know several web based application service providers that use the same method...

Are you saying that it can't be done?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 2:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No, it's not really possible, because most of the SQL hibernate issues is generated up-front at SessionFactory build time.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 2:39 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I can imagine that some patch for this would be easy to do.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 29, 2004 5:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
well - the pregenerated sql contains the hard core catalog name so not that easy.

But one thing that comes to mind is to use H3 entity names to map this - that would give you 1 session factory, but then x mappings per class...which also might not be optimal...I think i would use 2000 sessionfactories instead..

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 30, 2004 5:33 am 
Newbie

Joined: Mon Feb 02, 2004 8:27 pm
Posts: 17
hmm well this time next year it'll be 20,000 SessionFactories so I don't really think that's a feasible option..

I guess we'll just have to keep developing our own DAO generator
:(


Top
 Profile  
 
 Post subject: Hibernate 3.0 and Multiple Databases/Catalogs?
PostPosted: Sat May 03, 2008 5:28 am 
Newbie

Joined: Tue Apr 29, 2008 9:15 am
Posts: 4
max wrote:
well - the pregenerated sql contains the hard core catalog name so not that easy.

But one thing that comes to mind is to use H3 entity names to map this - that would give you 1 session factory, but then x mappings per class...which also might not be optimal...I think i would use 2000 sessionfactories instead..



But the pregenerated sql contains the hard core catalog only when

"hibernate.default_catalog" property is set. If we are not setting the property while session factory build up, catalog won't be appended with the query. Am i right????


Thanks & regards

unnis


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