• 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

Objects creation in Spring

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I have a question about Spring framework.
As you already know, we can use Spring to manage the dependencies for us.
So, instead of we create an object and pass it to another one, Spring will inject it through setXxx( ) method.
My question is, Whenever Spring calls setXxx( ) method, a new object created -through newInstance( )- ?
Consider this please, my object uses Hibernate to access a database, So what to pass to it ?
SessionFactory ? or just Session ?
AFAIK, SessionFactory is thread-safe and it is heavy to create.
But I'm thinking, how can I ask Spring to pass Session object since we can get it from the factory ?
Well, I'm asking for explaination please.
Thanks.
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Todd:
Hi.
I have a question about Spring framework.
As you already know, we can use Spring to manage the dependencies for us.
So, instead of we create an object and pass it to another one, Spring will inject it through setXxx( ) method.
My question is, Whenever Spring calls setXxx( ) method, a new object created -through newInstance( )- ?
Consider this please, my object uses Hibernate to access a database, So what to pass to it ?
SessionFactory ? or just Session ?
AFAIK, SessionFactory is thread-safe and it is heavy to create.
But I'm thinking, how can I ask Spring to pass Session object since we can get it from the factory ?
Well, I'm asking for explaination please.
Thanks.



If you're using Spring and Hibernate together you should be looking at Spring's HibernateTemplate class. It'll handle all that stuff for you, and you won't have to worry about Session or SessionFactory.
 
reply
    Bookmark Topic Watch Topic
  • New Topic