Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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.
 
I am Arthur, King of the Britons. And this is a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic