• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Objects creation in Spring

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
    Bookmark Topic Watch Topic
  • New Topic