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

SessionFactory returns same object everytime we call it?

 
Nishita Jain
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to know that if we call
SessionFactory sessionFactory = new Configuration().configure().buildSessionfactory();
n number of times in our project wil it retun same object? if yes then how?
I know that SessionFactory objects are immutable and object is return based on the given config params.

Thanks,
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Creating a new SessionFactory is a heavy weight operation, you should not be doing it more than once in your application.

If the SessionFactory uses an external configuration file and this changes then the object content will be different.
 
Nishita Jain
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply.
I know that heavy weight operation. I just want to know that if I call

SessionFactory sessionFactory = new Configuration().configure().buildSessionfactory();
n number of times in our project wil it retun same object? if answer is yes then how?

Cheers,
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the answer is no.
 
Nishita Jain
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh thanks
 
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
From a functional standpoint, you'll get 'the same object' in the sense that it will do 'the same thing.' However, from a Java/JVM perspective, it is not the same instance, but a completely new object.

Your JVM won't start spitting out errors if you do this, but it's not a good practice, and really only has drawbacks, as opposed to any real benefits.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic