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

📄 auditorrole1dao.java

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

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.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import gdpe.hibernate.department.*;
/**
 * Data access object (DAO) for domain model class AuditorRole1.
 * @see gdpe.hibernate.auro.AuditorRole1
 * @author MyEclipse - Hibernate Tools
 */
public class AuditorRole1DAO extends BaseHibernateDAO {

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

	//property constants

    
    public void save(AuditorRole1 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(AuditorRole1 persistentInstance) {
        log.debug("deleting AuditorRole1 instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public AuditorRole1 findById( gdpe.hibernate.auro.AuditorRole1Id id) {
        log.debug("getting AuditorRole1 instance with id: " + id);
        try {
            AuditorRole1 instance = (AuditorRole1) getSession()
                    .get("gdpe.hibernate.auro.AuditorRole1", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(AuditorRole1 instance) {
        log.debug("finding AuditorRole1 instance by example");
        try {
            List results = getSession()
                    .createCriteria("gdpe.hibernate.auro.AuditorRole1")
                    .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 AuditorRole1 instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from AuditorRole1 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 AuditorRole1 merge(AuditorRole1 detachedInstance) {
        log.debug("merging AuditorRole1 instance");
        try {
            AuditorRole1 result = (AuditorRole1) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(AuditorRole1 instance) {
        log.debug("attaching dirty AuditorRole1 instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(AuditorRole1 instance) {
        log.debug("attaching clean AuditorRole1 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 + -