• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If my hibernate-cfg.xml has multiple session factories then how can I Load appropriate SessionFactor

 
Rajendra Lella
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vivek,
apart from that is there any other way of invoking SessionFactory of another DB?

regards,
Rajendra
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vivek Singh
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic