How Spring is integrated with Hibernate

Viewed 175

I know how to configure Spring with hibernate.

But my question is how spring and hibernate integrate and how it works.

Below is the code that I used to create Spring + Hibernate application.

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
     <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.show_sql">false</prop>
        </props>
    </property>
</bean>

And this sessionFactory bean is injected in the java code,

import org.hibernate.SessionFactory;
public class DAOSupport extends HibernateDaoSupport {

@Autowired
public void createSessionFactory(SessionFactory sessionFactory) {
    setSessionFactory(sessionFactory);
}

As you can see that, Session Factory that I created with is associated with spring package but in code it is using hibernate package.

PS: I know HibernateDaoSupport is deprecated and this is just for understanding how both framework works.

Thanks Gimby for the link.JavaDoc

1 Answers
Related