📄 teacherdao.java
字号:
package com.dcs.hibernate;
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;
/**
* Data access object (DAO) for domain model class Teacher.
*
* @see com.dcs.hibernate.Teacher
* @author MyEclipse - Hibernate Tools
*/
public class TeacherDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(TeacherDAO.class);
// property constants
public static final String TEACH_NAME = "teachName";
public static final String TEACH_PASSWORD = "teachPassword";
public static final String TEACH_ADDR = "teachAddr";
public static final String TEACH_PHONE = "teachPhone";
public static final String TEACH_PHOTO_NAME = "teachPhotoName";
public void save(Teacher transientInstance) {
log.debug("saving Teacher instance");
Transaction transaction = null;
Session session = getSession();
try {
transaction = session.beginTransaction();
transaction.begin();
session.save(transientInstance);
log.debug("save successful");
transaction.commit();
} catch (RuntimeException re) {
log.error("save failed", re);
transaction.rollback();
throw re;
}
}
public void delete(Teacher persistentInstance) {
log.debug("deleting Teacher instance");
Transaction transaction = null;
Session session = getSession();
try {
transaction = session.beginTransaction();
transaction.begin();
session.delete(persistentInstance);
log.debug("delete successful");
transaction.commit();
} catch (RuntimeException re) {
log.error("delete failed", re);
transaction.rollback();
throw re;
}
}
public Teacher findById(java.lang.String id) {
log.debug("getting Teacher instance with id: " + id);
try {
Teacher instance = (Teacher) getSession().get(
"com.dcs.hibernate.Teacher", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Teacher instance) {
log.debug("finding Teacher instance by example");
try {
List results = getSession().createCriteria(
"com.dcs.hibernate.Teacher").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 Teacher instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Teacher 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 findByTeachName(Object teachName) {
return findByProperty(TEACH_NAME, teachName);
}
public List findByTeachPassword(Object teachPassword) {
return findByProperty(TEACH_PASSWORD, teachPassword);
}
public List findByTeachAddr(Object teachAddr) {
return findByProperty(TEACH_ADDR, teachAddr);
}
public List findByTeachPhone(Object teachPhone) {
return findByProperty(TEACH_PHONE, teachPhone);
}
public List findByTeachPhotoName(Object teachPhotoName) {
return findByProperty(TEACH_PHOTO_NAME, teachPhotoName);
}
public List findAll() {
try {
String queryString = "from Teacher as model";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException e) {
throw e;
}
}
public Teacher merge(Teacher detachedInstance) {
log.debug("merging Teacher instance");
Transaction transaction = null;
Session session = getSession();
try {
transaction = session.beginTransaction();
transaction.begin();
Teacher result = (Teacher) session.merge(detachedInstance);
log.debug("merge successful");
transaction.commit();
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
transaction.rollback();
throw re;
}
}
public void attachDirty(Teacher instance) {
log.debug("attaching dirty Teacher instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Teacher instance) {
log.debug("attaching clean Teacher 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 + -