• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SessionFactory returns same object everytime we call it?

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the answer is no.
 
Nishita Jain
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh thanks:)
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic