📄 role1dao.java
字号:
package gdpe.hibernate.role;
import java.util.List;
import java.util.Set;
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 Role1.
* @see gdpe.hibernate.role.Role1
* @author MyEclipse - Hibernate Tools
*/
public class Role1DAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(Role1DAO.class);
//property constants
public static final String CHROLENAME = "chrolename";
public static final String CHROLEDESC = "chroledesc";
public void save(Role1 transientInstance) {
log.debug("saving role 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(Role1 persistentInstance) {
log.debug("deleting Role1 instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Role1 findById( java.lang.String id) {
log.debug("getting Role1 instance with id: " + id);
try {
Role1 instance = (Role1) getSession()
.get("gdpe.hibernate.role.Role1", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Role1 instance) {
log.debug("finding Role1 instance by example");
try {
List results = getSession()
.createCriteria("gdpe.hibernate.role.Role1")
.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 Role1 instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Role1 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 findByChrolename(Object chrolename) {
return findByProperty(CHROLENAME, chrolename);
}
public List findByChroledesc(Object chroledesc) {
return findByProperty(CHROLEDESC, chroledesc);
}
public Role1 merge(Role1 detachedInstance) {
log.debug("merging Role1 instance");
try {
Role1 result = (Role1) getSession()
.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Role1 instance) {
log.debug("attaching dirty Role1 instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Role1 instance) {
log.debug("attaching clean Role1 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 + -