-->
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.  [ 7 posts ] 
Author Message
 Post subject: can i have two session factory in a single hibernate.cfg.xml
PostPosted: Mon Feb 19, 2007 1:50 am 
Newbie

Joined: Mon Feb 19, 2007 1:44 am
Posts: 8
Hi,

I want to know whether I can use two session factories in a single hibernate.cfg.xml file.
If I use that like so, then how can i specify in the Java code which session factory need to be used.


Thanks and Regadrs,
Jacob


Top
 Profile  
 
 Post subject: No U can not have
PostPosted: Mon Feb 19, 2007 2:34 am 
Newbie

Joined: Mon Feb 19, 2007 12:54 am
Posts: 16
Location: banglore, india
Hi Jacob,

U can not have two session factory tags in configuration XML.

In DTD it is specifies like this

<!ELEMENT hibernate-configuration (session-factory,security?)>
It means in hibernate-configuration u should have only one session-factory tag with optional security.

_________________
Banglore Developer


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 2:48 am 
Newbie

Joined: Mon Feb 19, 2007 1:44 am
Posts: 8
Thanks for your reply..
But, is there any way I can use two databases in a single java program using hibernate?

I need to write 2 configuration files whcih contains one session factory each and include these two corresponding files in program corresponding to the database i want to use?

Is there any other method other than this.

Also is it mandatory to keey the name of the xml file same as hibernate.cfg.xml ?

Thanks and Regards,
Jacob.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 3:02 am 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
You can have multiple databases in a single application. You can also specify multiple <session-factory> in a configuration file. But the easiest way would be to use 2 different configuration files. Then you can have as below

SessionFactory sf1 = new Configuration()
.configure("a.cfg.xml")
.buildSessionFactory();

SessionFactory sf2 = new Configuration()
.configure("b.cfg.xml")
.buildSessionFactory();

Hope that helps.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 3:08 am 
Newbie

Joined: Mon Feb 19, 2007 1:44 am
Posts: 8
Somu,

you answer was helpful, but can I know how can i use multuple session factories in a single configuration file and invoke the needed database in Java program. As per the first replier, its not possible..

Thanks and Regards,
Jacob.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 3:23 am 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
You cannot do directly. What you can do perhaps is read the single configuration file into 2 sessionfactories and update the JDBC settings into them. So probably have a single XML configuration file and have 2 different properties file having the JDBC settings.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 19, 2007 4:27 am 
Newbie

Joined: Mon Feb 19, 2007 1:44 am
Posts: 8
thanks somu


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