Be sure you have a transactionManager bean configured
Code:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"><ref local="sessionFactory"/></property>
</bean>
Also create a transactionTemplate if you want to do programmatic transaction management
Code:
<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
<property name="transactionManager"><ref bean="transactionManager"/></property>
</bean>
Once this is created, you can use the transactionTemplate bean like so:
Code:
Object result = transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
Employee emp = (Employee)getHibernateTemplate().load(Employee.class,new Integer(id));
//update
emp.setStatus("inactive");
return null;
}
});
Since the transaction template uses the HibernateTransactionManager, all executions will automatically be provided the Hibernate session, so you don't have to do it yourself.
Read the docs that cover this thoroughly:
http://static.springframework.org/sp...n.html#d0e4797
You should also grab a book or three on Spring, along with the Hibernate book (supports the developers, too).
(Disclaimer: I'm writing this from memory and haven't tested the code shown above.)