Why not get rid of SQL altogether? Hibernate provides for this.
Are you familiar with the DAO design pattern? Basically you define a class for working with a specific object type. Spring makes this pretty easy by allowing you to subclass HibernateDaoSupport. IE:
Code:
public class MyObjectDAOImpl extends HibernateDaoSupport {
public void persistNewMyObject(MyObject value) {
this.getHibernateTemplate().persist(value);
}
}
All you need to do is inject the session factory into that object via Spring like so:
Code:
<bean id="whateverBean" class="com.persistence.MyObjectDAOImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
And you're ready to go. You can then create your own methods in that class relating to persistence. HibernateDaoSupport defines a bunch of simple methods for getting access to a session or session factory via getSession and getSessionFactory.
Then, use something like this in a method to update your object:
Code:
Session session = this.getSessionFactory().openSession();
Transaction trans = session.beginTransaction();
//You should probably wrap a try..catch block around the following.
MyObject object = (MyObject)session.get(MyObject.class, 1);
object.setDescription("IBM");
session.update(object);
trans.commit();
session.disconnect();
[/code]