-->
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: Multiple databases and common mappings
PostPosted: Wed Aug 18, 2004 12:41 pm 
Newbie

Joined: Fri Apr 02, 2004 2:22 pm
Posts: 11
Hibernate version: v. 2.1.4
Name and version of the database you are using: mySQL v4.0.16


My application needs to have the ability to connect to different mysql databases depending on the client logging into the application. In searching the forum and reading the documentaion I know this is possible using multiple SessionFactory instances and multiple hibernate.cfg.xml files but I'm don't see an exact solution to my problem.

Each database is configured identically but does not share data between customers. I'd like, however, to have the ability to specify a single hibernate.cfg.xml file that contains the mappings and other common properties used by the application and only specify a different database connection URL for the session factory. In other words, I don't want to have to create a complete hibernate.cfg.xml for each customer because if a mapping change in the .xml is required, that would end up being too many files to maintain.

Is it simply a matter of specifying a database connection URL in for the Configuration of the sessionFactory? Any examples out there?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 1:45 pm 
Beginner
Beginner

Joined: Mon Nov 24, 2003 5:39 am
Posts: 26
Location: France
Try the Spring framework for easy switching betweeen datasources while maintaining mapping definitions.
You could also set up a filter in Ant or Maven that replaces your datasources connection info at build time.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 3:03 pm 
Newbie

Joined: Fri Apr 02, 2004 2:22 pm
Posts: 11
Thanks for the reply. Unfortunately, I'm not familar with the Spring framework and have limited time on getting something implemented so not sure if I could that up and working in time.

Is there another alternative?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 3:14 pm 
Beginner
Beginner

Joined: Mon Nov 24, 2003 5:39 am
Posts: 26
Location: France
Try to generate different configuration files from one master configuration file. Ant's filter task allows you to replace occurences of a string in a file. You could thus, add @hibernate.datasource@ to your master configuration file and replace it with whatever value you need for your different configurations.


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.