I'm not sure what you mean by transaction code but I am pasting in the code that is used in my DAO classes. Basically I am using something called a HibernateTemplate that is part of the spring framework. I think the Spring class HibernateDAOSupport, which is extended somewhere, creates the session . . . I don't know if anyone here is familiar with Spring but here is the code anyway, hope this helps:
public class PersonDAOHibernate extends BaseDAOHibernate implements PersonDAO {
public Person getPerson(Long id) {
Person person = (Person) getHibernateTemplate().get(Person.class, id);
if (person == null) {
throw new ObjectRetrievalFailureException(Person.class, id);
}
return person;
}
public void savePerson(Person person) {
getHibernateTemplate().saveOrUpdate(person);
}
public void removePerson(Long id) {
// object must be loaded before it can be deleted
getHibernateTemplate().delete(getPerson(id));
}
}
|