• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

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.
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!