⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttestdao.java

📁 持久层hibernate技术使用的一个例子
💻 JAVA
字号:
package cn.hope.front.pojo.dao;




import java.util.List;

import org.apache.log4j.Logger;

import net.sf.hibernate.HibernateException;



import cn.hope.front.pojo.TTest;




import cn.hope.front.pojo.base.BaseTTestDAO;



public class TTestDAO extends BaseTTestDAO {
	Logger log = Logger.getLogger(TTestDAO .class.getName());
	/**
	 * Default constructor.  Can be used in place of getInstance()
	 */
	public TTestDAO () {
		
	}
	public Integer insert(TTest tTest) throws HibernateException {
		try {
			initialize();// 初始化session
			return this.save(tTest);// 调用生成好的父类方法save(),返回被插入数据的主键
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();// 关闭当前session
		}
	}
	

	public List searchByKey(String info,String tq) throws HibernateException {
		List list = null;
		TTest tTest = new TTest();
		String sqlStr = "select tTest from TTest tTest where tTest.flag='0' and tTest.TTestInfo.TTestid="+info+" and tTest.TQuestion.tqId="+tq;
		try {
			initialize();
			list = this.getSession().find(sqlStr);
			if (list.size() > 0) {
				tTest = (TTest) list.get(0);
				System.out.println(tTest+"!!!!!!!!!!!!!!@@@@@@@@@@@@@@@@@@");
			}
			
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
		return list;
	}

	public List U01D2120Tquest(String TTestid) throws HibernateException {
		List list = null;
		String sqlStr = "from TTest t where t.flag='0' and t.TTestInfo.TTestid='"+TTestid+"'";
		try {
			initialize();
			list = this.getSession().find(sqlStr);
		} catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
		}
		return list;
	}
	


}

⌨️ 快捷键说明

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