orderstatedao.java

来自「基于struts+hibernate的电子商务网站。可运行。数据库mysql」· Java 代码 · 共 66 行

JAVA
66
字号
package tarena.dao;

import org.hibernate.Session;

import tarena.entity.Orderstate;
public class OrderstateDAO extends BaseHibernateDAO {
	
	public static final String STATE_NUM = "snum";
	
	public void save(Orderstate transientInstance) {		
		Session session = getSession();
		try {
			session.beginTransaction().begin();
			session.saveOrUpdate(transientInstance);
			session.getTransaction().commit();
		} catch (RuntimeException re) {	
			session.getTransaction().rollback();
			throw re;
		} finally{
			closeSession();
		}
	}

	public void delete(Orderstate persistentInstance) {
		Session session = getSession();
		try {
			session.beginTransaction().begin();
			getSession().delete(persistentInstance);
			session.getTransaction().commit();			
		} catch (RuntimeException re){	
			session.getTransaction().rollback();
			throw re;
		} finally{
			closeSession();
		}
	}

	public Orderstate findById(Integer id) {		
		Session session = getSession();
		try {
			Orderstate instance = (Orderstate) session.get(
					"tarena.entity.Orderstate", id);			
			return instance;
		} catch (RuntimeException re) {
			return null;
		}finally{
			closeSession();
		}
	}
	
	public Orderstate findByOrdernum(Integer ordernum){
		Session session = getSession();
		try {
			Orderstate instance = (Orderstate) session
								  .createQuery("from Orderstate os where os."+STATE_NUM+"=? ")
								  .setParameter(0, ordernum)
								  .uniqueResult();
			return instance;
		} catch (RuntimeException re) {
			return null;
		}finally{
			closeSession();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?