81,092
社区成员
发帖
与我相关
我的任务
分享
public boolean save(Object obj) throws HibernateException,
NumberFormatException {
return Integer.parseInt(this.getSession().save(obj) + "") > 0 ? true
: false;
}
/*
* (non-Javadoc)
*
* @see com.boxun.crm.dao.IDao_Hql#update(java.lang.Object)
*/
public boolean update(Object obj) throws HibernateException {
if (null == obj) {
return false;
}
this.getSession().update(obj);
return true;
}
package cn.com.hibernate.dao.impl;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import cn.com.hibernate.dao.DeptDao;
import cn.com.hibernate.vo.Dept;
public class DeptDaoImpl extends HibernateDaoSupport implements DeptDao {
// private static SessionFactory factory = null;
//
// static {
// Configuration cfg = new Configuration();
// cfg.configure();
// factory = cfg.buildSessionFactory();
// }
public void addDept(Dept dept) {
// Transaction tx = null;
// Session session = null;
// try {
// session = factory.openSession();
// tx = session.beginTransaction();
// session.save(dept);
// tx.commit();
// session.close();
// } catch (HibernateException e) {
// tx.rollback();
// throw new RuntimeException(e);
// }
try {
this.getHibernateTemplate().save(dept);
} catch (DataAccessException e) {
throw new RuntimeException(e);
}
}
public void deleteDept(Integer id) {
try {
this.getHibernateTemplate().delete(find(id));
} catch (DataAccessException e) {
throw new RuntimeException(e);
}
}
public Dept find(Integer id) {
try {
return (Dept) this.getHibernateTemplate().load(Dept.class, id);
} catch (DataAccessException e) {
throw new RuntimeException(e);
}
}
public void updateDept(Dept dept) {
try {
this.getHibernateTemplate().update(dept);
} catch (DataAccessException e) {
throw new RuntimeException(e);
}
}
}
姓名 | <input id="user" name="user" type="text" /></td> |
密码 | <input id="psw" name="psw" type="text" /></td> |
<input type="submit" value="提交"/><input type="button" value="返回" /> |