This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi, I'm integrating Hibernate to Spring based on plain Hibernate3 and I have a understanding problem with DI.
My question is: The method setSessionFactory has an argument of SessionFactory and what we are injecting as setter DI, is an instance of LocalSessionFactoryBean which is surely not implemeting org.hibernate.SessionFactory interface. How things are working here?
Quite simple here. the LocalSessionFactoryBean implements FactoryBean, which is a special interface for Spring. Spring sees that the type of that class is a FactoryBean, so instead of creating the instance of LocalSessionFactoryBean, it calls the special public Object getObject() method, and the object that that returns is what is given out. It is the Factory pattern at work.
So LocalSessionFactoryBean's getObject() method returns a SessionFactory object.