⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auditor1dao.java

📁 hibernate应用测试,初学hibernate 的会员可以看看.
💻 JAVA
字号:
package gdpe.hibernate.auditor1;

import gdpe.hibernate.department.*;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.hibernate.Session;
//import org.hibernate.SessionFactory;
//import org.hibernate.cfg.Configuration;
import org.hibernate.Transaction;
/**
 * Data access object (DAO) for domain model class Auditor1.
 * @see gdpe.hibernate.auditor1.Auditor1
 * @author MyEclipse - Hibernate Tools
 */
public class Auditor1DAO extends BaseHibernateDAO {

    private static final Log log = LogFactory.getLog(Auditor1DAO.class);

	//property constants
	public static final String CHAUDITORNAME = "chauditorname";
	public static final String CHSEX = "chsex";
	public static final String CHAUDITORLEVEL = "chauditorlevel";
	public static final String CHBEGINAUDITDATE = "chbeginauditdate";
	public static final String CHPASSWORD = "chpassword";
	public static final String CHDWCODE = "chdwcode";
	public static final String CHSTATUS = "chstatus";
	public static final String CHLEAVEDATE = "chleavedate";
	public static final String CHMODIFIER = "chmodifier";
	public static final String CHMODIFYDATE = "chmodifydate";

    
    public void save(Auditor1 transientInstance) {
 
        log.debug("saving Auditor1 instance");
		Transaction tx = null;
		Session session = getSession();
		try {
			tx = session.beginTransaction();
			session.save(transientInstance);
			tx.commit();
			// endTransaction(true);
			System.out.println("------------>增加成功");
			log.debug("增加成功");
		} catch (RuntimeException re) {
			tx.rollback();
			log.error("save failed", re);
			throw re;

		} finally {
			close(session);
		}

    }
    
	public void delete(Auditor1 persistentInstance) {
        log.debug("deleting Auditor1 instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Auditor1 findById( java.lang.String id) {
        log.debug("getting Auditor1 instance with id: " + id);
        try {
            Auditor1 instance = (Auditor1) getSession()
                    .get("gdpe.hibernate.auditor1.Auditor1", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(Auditor1 instance) {
        log.debug("finding Auditor1 instance by example");
        try {
            List results = getSession()
                    .createCriteria("gdpe.hibernate.auditor1.Auditor1")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Auditor1 instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Auditor1 as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByChauditorname(Object chauditorname) {
		return findByProperty(CHAUDITORNAME, chauditorname);
	}
	
	public List findByChsex(Object chsex) {
		return findByProperty(CHSEX, chsex);
	}
	
	public List findByChauditorlevel(Object chauditorlevel) {
		return findByProperty(CHAUDITORLEVEL, chauditorlevel);
	}
	
	public List findByChbeginauditdate(Object chbeginauditdate) {
		return findByProperty(CHBEGINAUDITDATE, chbeginauditdate);
	}
	
	public List findByChpassword(Object chpassword) {
		return findByProperty(CHPASSWORD, chpassword);
	}
	
	public List findByChdwcode(Object chdwcode) {
		return findByProperty(CHDWCODE, chdwcode);
	}
	
	public List findByChstatus(Object chstatus) {
		return findByProperty(CHSTATUS, chstatus);
	}
	
	public List findByChleavedate(Object chleavedate) {
		return findByProperty(CHLEAVEDATE, chleavedate);
	}
	
	public List findByChmodifier(Object chmodifier) {
		return findByProperty(CHMODIFIER, chmodifier);
	}
	
	public List findByChmodifydate(Object chmodifydate) {
		return findByProperty(CHMODIFYDATE, chmodifydate);
	}
	
    public Auditor1 merge(Auditor1 detachedInstance) {
        log.debug("merging Auditor1 instance");
        try {
            Auditor1 result = (Auditor1) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Auditor1 instance) {
        log.debug("attaching dirty Auditor1 instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Auditor1 instance) {
        log.debug("attaching clean Auditor1 instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -