Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate: Two SessionFactories per cfg file

 
vipin jain
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we create more then two session Factory using single Hbm and cfg file if yes then how we can do this?

[ December 09, 2008: Message edited by: vipin jain ]

[ Edited to give this a meaningful title - Paul Sturrock ]
[ December 09, 2008: Message edited by: Paul Sturrock ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. The DTD only allows one session-factory element per hibernate-configuration. You can use multiple configuration files, or configure these programatically. You don't use hbm fiels to configure the session factory itself, these are used to map classes.
[ December 09, 2008: Message edited by: Paul Sturrock ]
 
Emmanuel Bernard
author
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Paul is right. People usually tend to do the following:
Share the hbm.xml files or the annotations across multiple SessionFactory or EntityManagerFactory but create one distinct cfg.xml file per SessionFactory they want to create. This makes sense as usually the datasource is different between those. You can also adjust some properties programmatically after reading a cfg.xml file but this approach is less common.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic