File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate Configuration help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Configuration help!" Watch "Hibernate Configuration help!" New topic
Author

Hibernate Configuration help!

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9353
    
    2

Can we have two cfg.xml files for the same project?? What effect would that make? The below is from the Hibernate Documentation.

With the XML configuration, starting Hibernate is then as simple as
SessionFactory sf = new Configuration().configure().buildSessionFactory();

You can pick a different XML configuration file using
SessionFactory sf = new Configuration()
.configure("catdb.cfg.xml")
.buildSessionFactory();


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes. With two configurations you can have two different SessionFactories.
[ July 05, 2007: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9353
    
    2

But what would that mean to my application using two sessionfactories with each connecting to different database. So that means I can connect to two different databases imagining I have configured them appropriately in the hibernate1.cfg.xml file (with properties set to connect to oracle db) and hibernate2.cfg.xml file (with properties set to connect to mysql db)?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes, two SessionFactories would enable your application to persist to two differernt databases.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9353
    
    2

Thanks for the reply!
 
 
subject: Hibernate Configuration help!