package hibernate3.object;
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;
/**
* A data access object (DAO) providing persistence and search support for
* Employee entities. Transaction control of the save(), update() and delete()
* operations can directly support Spring container-managed transactions or they
* can be augmented to handle user-managed Spring transactions. Each of these
* methods provides additional information for how to configure it for the
* desired type of transaction control.
*
* @see hibernate3.object.Employee
* @author MyEclipse Persistence Tools
*/
public class EmployeeDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(EmployeeDAO.class);
// property constants
public static final String NAME = "name";
public static final String ADDRESS = "address";
public static final String TITLE = "title";
public static final String SALARY = "salary";
public void save(Employee transientInstance) {
log.debug("saving Employee instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Employee persistentInstance) {
log.debug("deleting Employee instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Employee findById(java.lang.Integer id) {
log.debug("getting Employee instance with id: " + id);
try {
Employee instance = (Employee) getSession().get(
"hibernate3.object.Employee", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByExample(Employee instance) {
log.debug("finding Employee instance by example");
try {
List results = getSession().createCriteria(
"hibernate3.object.Employee").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 Employee instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Employee 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 findByName(Object name) {
return findByProperty(NAME, name);
}
public List findByAddress(Object address) {
return findByProperty(ADDRESS, address);
}
public List findByTitle(Object title) {
return findByProperty(TITLE, title);
}
public List findBySalary(Object salary) {
return findByProperty(SALARY, salary);
}
public List findAll() {
log.debug("finding all Employee instances");
try {
String queryString = "from Employee";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
public Employee merge(Employee detachedInstance) {
log.debug("merging Employee instance");
try {
Employee result = (Employee) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Employee instance) {
log.debug("attaching dirty Employee instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Employee instance) {
log.debug("attaching clean Employee instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Hibernate3.rar (29个子文件)
Hibernate3
.project 723B
bin
hibernate3
HibernateSessionFactory.class 2KB
HibernateTest.class 2KB
object
EmployeeDAO.class 6KB
Employee.hbm.xml 1KB
Employee.class 2KB
BaseHibernateDAO.class 503B
IBaseHibernateDAO.class 182B
Department.class 1KB
Department.hbm.xml 857B
DepartmentDAO.class 5KB
hibernate.cfg.xml 963B
department.sql 141B
src
hibernate3
HibernateTest.java 2KB
object
Employee.hbm.xml 1KB
BaseHibernateDAO.java 358B
Employee.java 2KB
Department.java 1KB
DepartmentDAO.java 4KB
EmployeeDAO.java 4KB
IBaseHibernateDAO.java 228B
Department.hbm.xml 857B
HibernateSessionFactory.java 3KB
hibernate.cfg.xml 963B
hibernate.reveng.xml 546B
.classpath 391B
.myhibernatedata 459B
Employee.sql 295B
lib
mysql.jar 515KB
共 29 条
- 1
资源评论
zhi070202021016
- 粉丝: 6
- 资源: 58
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功