Using Hibernate Synchronizer 3.1.1 with Spring, Hibernate 2 and < JRE 1.5

The following steps assume you have already installed the Hibernate Synchronizer in Eclipse:

1) Update the Hibernate Synchronizer to use a custom base root (Source Code)

From Menu bar: Project->Properties->Hibernate Synchronizer->Data Access Objects tab->Check “I would like to use a custom root” and enter full path to the SpringBaseRootDAO

2) Update the Hibernate Synchronizer to use a custom Exception class
Same location as above. Enter “org.springframework.dao.DataAccessException” for DAO Exception input box

3) Update Base DAO Snippets
a) On Eclipse Menu bar, click Window->Preferences
b) Click Hibernate Synchronizer on left panel
c) Click Snippets
d) Expand Base DAO
e) Replace Action Methods with this

f) Replace Finder Methods with this
g) Replace Imports with this
h) Replace Required Methods with this

4) Configure your generated DAO(s) to inject a LocalSessionFactory for HibernateTemplate’s “sessionFactory” property (SpringBaseRootDAO extends HibernateTemplate). For example, an entry in the applicationContext.xml might look like:

<bean id=”usersDataAccessObject” class=”com.xyz.data.dao.UsersDAO”>
<property name=”sessionFactory”>
<ref local=”mySessionFactory”/>
</property>
</bean>

Of course, the above example assumes you have “mySessionFactory” bean defined.

These changes are geared toward an environment still using Hiberate 2 and JRE/JDK 1.4 and below.

Also, I added this interceptor to the applicationContext.xml file:

<bean class=”org.springframework.orm.hibernate.HibernateInterceptor” id=”hibernateInterceptor”>
<bean id=”hibernateInterceptor” class=”org.springframework.orm.hibernate.HibernateInterceptor”>
<property name=”sessionFactory”>
<ref bean=”mySessionFactory”/>
</property>
</bean>

My gut tells me there is still some kinks to work out, but I’m up and running with it now. Hopefully, it helps us out. Let me know if you have ideas to improve it.

ServiceCycle is a registered trademark of Supergloo, inc..