📄 articledao.java
字号:
package org.openblog.hibernate;
import java.util.List;
import java.util.Set;
import org.hibernate.Transaction;
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.criterion.Example;
/**
* A data access object (DAO) providing persistence and search support for
* Article 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 org.openblog.hibernate.Article
* @author MyEclipse Persistence Tools
*/
public class ArticleDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(ArticleDAO.class);
// property constants
public static final String ARTICLE_TITLE = "articleTitle";
public static final String ARTICLE_CONTENT = "articleContent";
public static final String ARTICLE_DATE = "articleDate";
public static final String ARTICLE_COUNT = "articleCount";
public void save(Article transientInstance) {
Transaction trans = null;
log.debug("saving Article instance");
try {
trans = getSession().beginTransaction();
getSession().save(transientInstance);
getSession().flush();
trans.commit();
log.debug("save successful");
} catch (RuntimeException re) {
if(trans!=null) trans.rollback();
log.error("save failed", re);
throw re;
}
}
public void delete(Article persistentInstance) {
Transaction trans = null;
log.debug("deleting Article instance");
try {
trans = getSession().beginTransaction();
getSession().delete(persistentInstance);
getSession().flush();
trans.commit();
log.debug("delete successful");
} catch (RuntimeException re) {
if(trans!=null) trans.rollback();
log.error("delete failed", re);
throw re;
}
}
public void ModifyArticle(Article article)
{
Session session = HibernateSessionFactory.getSession();
org.hibernate.Transaction ts = null;
try
{
ts= session.beginTransaction();
session.update(article);
ts.commit();
}
catch(Exception ex)
{
if(ts!=null) ts.rollback();
System.out.println("
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -