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
分享到:
评论