public class TestOgi1DaoImpl extends HibernateDaoSupport implements TestOgi1Dao{
public boolean save(TestOgi1 transientInstance) {
log.debug("saving TestOgi1 instance");
Session session = null;
Transaction tx = null;
try {
// System.out.println(this.getHibernateTemplate().getSessionFactory().getCurrentSession());
// getHibernateTemplate().merge(transientInstance);
session = this.getSession(true);
tx = session.beginTransaction();
session.save(transientInstance);
tx.commit();
log.debug("save successful");
return true;
} catch (RuntimeException re) {
log.error("save failed", re);
tx.rollback();
throw re;
} finally {
if (session.isOpen()) {
session.close();
}
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding TestOgi1 instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from TestOgi1 as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
}
<bean id="userInfoDao" class="com.yuorCompany.C3p0.dao.userinfo.impl.UserInfoDaoImpl"> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> </bean>
Spring与Hibernate集成中的session问题
转: http://www.iteye.com/topic/733971
本文深入探讨了Spring与Hibernate集成中的session问题,包括如何在事务中使用session进行持久化操作,以及如何处理异常确保数据一致性。通过实例演示了save方法的实现,以及在查找特定属性值的对象时的find方法。同时,介绍了如何配置sessionFactory和事务管理。
616

被折叠的 条评论
为什么被折叠?



