• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

only one SessionFactory Object per application right?

 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session Factory is thread safe so there is only one object of sessionFactory is available through out the run right.

thanks
 
krishna bala
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you talking about , hibernate session factory ?
 
sudheer kiran
Ranch Hand
Posts: 237
Firefox Browser MyEclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes
my doubt is can we have only one session factory object or as many as we like?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not sure.since i am newbie to hibernate. but i read that SessionFactory is a Singleton and it create Session in heavyweight process
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally it would be one SessionFactory per DataSource. Your application may have more than one DataSource so you may have more than one SessionFactory in that instance. But you would not want to create a SessionFactory more than once in an application
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SessionFactory is a pretty resource heavy component, so you don't want to create multitudes of them. As was stated, one per datasource, or one per database if you have multiple databases, is usually when you have multiples. The Hiberante Session on the other hand is very resource friendly, and you can create lots of them!

-Cameron McKenzie
 
imam tunduru
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session factory object is implemented using the singleton design pattern. Instances of SessionFactory are thread-safe and typically shared throughout an application. As these objects are heavy weight because they contains the connection information, hibernate configuration information and mapping files location path. So creating number of instances will make our application heavy weight. But the session objects are not thread safe. Tag line is - SessionFactory objects are one per application and Session objects are one per client.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
imam tunduru wrote:Session factory object is implemented using the singleton design pattern.

No, its not.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic