-->
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.  [ 4 posts ] 
Author Message
 Post subject: using multiple database-schemes
PostPosted: Mon Jul 03, 2006 4:47 am 
Newbie

Joined: Mon Jul 03, 2006 4:36 am
Posts: 4
hello,

has somebody an example using different database-schemes?
Is it necessary to create one hibernate.cfg.xml per scheme?
How do I handle the two different sessions?

Thank you for your help,
Nino


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 6:19 am 
Beginner
Beginner

Joined: Thu Apr 07, 2005 5:12 pm
Posts: 27
Location: Hamburg
In case of postgres for example just type the name of the scheme before your table, eg.g scheme1.myTable, scheme2.mytable.
Oracle should work same.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 6:32 am 
Beginner
Beginner

Joined: Wed Feb 04, 2004 5:21 pm
Posts: 37
I use it on MySQL, it works just fine.

The way I do is with several singletons that have a sessionfactory configured with the correct schema and O/R mapping classes on each.

I handle the two different sessions independently of eachother by having

public final ThreadLocal<Session> currentSessionHolder = new ThreadLocal<Session>();

defined in each of the singletons.

Since I use Spring to manage my singletons, I use an init() and cleanup() method to configure and close open sessions.

For http request cycle handling I register the singletons as ApplicationListeners and implement

public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof RequestHandledEvent) {
closeCurrentSessionIgnore();
}
}

Voila, sessions are closed after servlets have handled the requests(provided I configure the proper servletfilter).

Henrik


Top
 Profile  
 
 Post subject: example?
PostPosted: Mon Jul 03, 2006 8:23 am 
Newbie

Joined: Mon Jul 03, 2006 4:36 am
Posts: 4
Thanks for your answer.

Is it possible for you to post the code-snippet of your configuration?
You configure the session directly in your code, not in the hibernate.cfg.xml?

Thank you!


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