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: Change connection, database name at runtime?
PostPosted: Wed Jul 05, 2006 9:45 am 
Newbie

Joined: Wed Jul 05, 2006 9:28 am
Posts: 10
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.3

Is it possible to change the connection.url at runtime?

I've got sixteen databases spread across two servers. Depending on parms passed into my application, I will need to change the connection.url and the database name at runtime.

Is there any way to do this in Hibernate? I looked in the API docs for Session, but don't see any way to set these at runtime.

Thanks,
Curt


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 2:13 pm 
Beginner
Beginner

Joined: Mon Jul 26, 2004 4:29 pm
Posts: 45
Location: TX, USA
We use the Spring Framework in conjunction with Hibernate to do something similar. You can configure the different data sources in the Spring Application Context and then choose which one based on your application's needs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 1:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
two options:

if you don't use 2nd level cache, use a custom ConnectionProvider that knows how to choose amongst them.

if you use 2nd level cache, change the connection parameters on the Configuration object and build another sessionfactory.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 06, 2006 10:24 am 
Newbie

Joined: Wed Jul 05, 2006 9:28 am
Posts: 10
Max, changing the connection properties on the Configuration object was the perfect solution.

Thanks!

Curt


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.