| Author |
If my hibernate-cfg.xml has multiple session factories then how can I Load appropriate SessionFactor
|
Rajendra Lella
Greenhorn
Joined: Oct 29, 2009
Posts: 9
|
|
Hi,
Can any one please tell if my hibernate-cfg.xml has multipe SessionFactories like
<hibernate-configuration>
<session-factory>
-- Connection to oracle
</session-factory>
<session-factory>
-- Connection to MySql
</session-factory>
<session-factory>
-- Connection to Sybase DB
</session-factory>
<session-factory>
-- Connection to Other DB
</session-factory>
Here How can I load the appropriate DB in my Code
Like I want to open Connection to Oracle in My code
Configuration con = new Configuration().configure();
SessionFactory sf = con.buildSessionFactory();// Here how can I load the appropriate DB Like (oracle,Sybase .. etc)
|
 |
Vivek Singh
Ranch Hand
Joined: Oct 27, 2009
Posts: 92
|
|
Rajendra Lella wrote:Hi,
Can any one please tell if my hibernate-cfg.xml has multipe SessionFactories like
<hibernate-configuration>
<session-factory name=>
-- Connection to oracle
</session-factory>
<session-factory >
-- Connection to MySql
</session-factory>
<session-factory>
-- Connection to Sybase DB
</session-factory>
<session-factory>
-- Connection to Other DB
</session-factory>
Here How can I load the appropriate DB in my Code
Like I want to open Connection to Oracle in My code
Configuration con = new Configuration().configure();
SessionFactory sf = con.buildSessionFactory();// Here how can I load the appropriate DB Like (oracle,Sybase .. etc)
One way is to use different oracle.cfg.xml mysql.cfg.xml configuration file.
And then
The same can be acheived in on cfg fille also using the sessionFactory name tag..
hope it helps you i am also learning Hibernate.
|
 |
Rajendra Lella
Greenhorn
Joined: Oct 29, 2009
Posts: 9
|
|
Vivek,
apart from that is there any other way of invoking SessionFactory of another DB?
regards,
Rajendra
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
You can't define a configuration file that contains more than one session factory; a hibernate-configuration element can only contain one session-factory according to the dtd. You can define more than one configuration file, as VivekSingh points out. Alternatively you can programatically build your sessions factories (see the Configuration API).
Normally you would not define your connection in your session factory, you would define it as a DataSource and refer to the DataSource from your configuration.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Vivek Singh
Ranch Hand
Joined: Oct 27, 2009
Posts: 92
|
|
Paul Sturrock wrote:You can't define a configuration file that contains more than one session factory;
Yes its true i think, i have checked lot of places but its not possible to define all sessionFactory in one cfg.xml file.
|
 |
 |
|
|
subject: If my hibernate-cfg.xml has multiple session factories then how can I Load appropriate SessionFactor
|
|
|