-->
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: hibernate and multiple database
PostPosted: Mon Dec 22, 2003 10:05 am 
Newbie

Joined: Mon Dec 22, 2003 10:00 am
Posts: 11
Location: Switzerland
Hi,
I use the same hibernate instance to access multiple databases (with the same structure, just different instances). To achieve this I have as many session factories (with provided Connections) as databases.
I would like to know if this is a safe pattern and if it is possible to enable caching (i.e. a separate cache for each database/session factory). The docs tell abount a JVM level cache which wouldn't be approriate for this case.
Thank you!
Massimo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 23, 2003 6:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
A sessionFactory for each database is correct. You are replicating though Hibernate I assume since they are the same structure. I would suggest you have XA data sources setup for each database. Caching should be fine in this situation.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 23, 2003 9:19 am 
Newbie

Joined: Mon Dec 22, 2003 10:00 am
Posts: 11
Location: Switzerland
Thank you for your answer, david.

Actually I'm, not replicating the database.
It is a servlet based application that supports more "accounts", every account is practically a different application with its own data (i.e. database), so I do not need XA since there is no transfer of data between databases.

Just to be sure I understood: the documentation says that the Second Level Cache is a JVM level cache. What I need is a "Session Factory level cache", i.e. a completely isolated cache for every session factory I instantiate.
But a JVM level cache is shared between session factories, that is I can't use it, or am I wrong?

Thank you
Massimo


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 23, 2003 8:36 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The JVM cache can be used optionally - you don't have to use it. I don't understand your requirements but I don't see that this level of caching to be that important. In anycase, some of the cache options do allow you to configure caching regions so you can isolate (and with it control) the location and cache behaviour.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 8:40 pm 
Newbie

Joined: Mon Feb 02, 2004 8:27 pm
Posts: 17
Hi there,

Is anyone still following this thread?

I have a similar situation to mapofe. We have a system where a descision was made some time ago (4 years) to have a separate database for each "account". This was done in the interest of speed is becuase the volume of data per account is quite significant.

I am currently looking at object/relational mapping and am wondering how this configuration will work (if at all) with Hibernate. I have read that we can at least achieve the multiple database requirement by creating new SessionFactory's for each database. However, we have over 1000 databases and my concern is that this will be very memory intensive.

Does anyone have any advice to offer on this subject?

Regards,

-M-


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 8:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Why exactly do you need multiple SessionFactorys?

If you are providing yr own connection, why not just have 1?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 9:09 pm 
Newbie

Joined: Mon Feb 02, 2004 8:27 pm
Posts: 17
Ok so if I create sessions using the sessionFactory().openSession(Connection conn) I can open up sessions with different database connections.. You don't think there will be any memory implications due to the large number of databases? (Maybe cache issues etc?)

I'm going to start doing some testing later this week.. It'll be interesting to see what the performance is like - we host a pretty high volume application service (still getting by on MySQL tho!)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 9:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Are you using the second-level cache?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 9:23 pm 
Newbie

Joined: Mon Feb 02, 2004 8:27 pm
Posts: 17
Probably not right now but it's something I'll need to consider in the future...

For now, a transaction level cache will probably suffice.


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.