| Author |
Objects creation in Spring
|
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3334
|
|
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.
|
 |
Michael Duffy
Ranch Hand
Joined: Oct 15, 2005
Posts: 163
|
|
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.
|
%
|
 |
 |
|
|
subject: Objects creation in Spring
|
|
|