Hibernate增删查该业务处理
package com.oa.manager.impl;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.oa.manager.OrgManager;
import com.oa.model.Organization;
public class OrgManagerImpl extends HibernateDaoSupport implements OrgManager {
/**添加***/
public void addOrg(Organization org, int parentId) {
if(parentId!=0){
org.setParent((Organization)this.getHibernateTemplate()
.load(Organization.class, parentId));
}
this.getHibernateTemplate().save(org);
}
/**删除***/
public void deleteOrg(int orgId) {
this.getHibernateTemplate().delete(
this.getHibernateTemplate().load(Organization.class, orgId));
}
/**查询***/
public Organization findOrg(int orgId) {
return (Organization)this.getHibernateTemplate().load(Organization.class, orgId);
}
/**List集合查询***/
@SuppressWarnings("unchecked")
public List<Organization> findOrgs(int parentId) {
if(parentId==0){
return this.getHibernateTemplate().find("from Organization o where o.parent is null");
}
return this.getHibernateTemplate().find("from Organization o where o.parent.id= ?", parentId);
}
/**修改***/
public void modifyOrg(Organization org, int parentId) {
if(parentId!=0){
org.setParent((Organization)this.getHibernateTemplate()
.load(Organization.class, parentId));
}
this.getHibernateTemplate().update(org);
}
}