tfiletypedao.java

来自「持久层hibernate技术使用的一个例子」· Java 代码 · 共 69 行

JAVA
69
字号
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.TFileType;
import cn.hope.front.pojo.base.BaseTFileTypeDAO;

public class TFileTypeDAO extends BaseTFileTypeDAO {
	Logger log = Logger.getLogger(TFileTypeDAO.class.getName());
	public static void main(String[] args) {
		TFileTypeDAO TFileTypeDAO=new TFileTypeDAO();
		try {
			TFileTypeDAO.searchByKey(new Integer(1));
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * Default constructor. Can be used in place of getInstance()
	 */
	public TFileTypeDAO() {
	}
	
	public TFileType searchByKey(Integer key)throws HibernateException
	{
		TFileType tft=new TFileType();
		try
		{
			initialize();
			tft=this.load(key);
			/*
			 * 强制延迟加载方法
			 * 	this.getSession().refresh(tft);
			 *	Hibernate.initialize(tft.getTFileType2s());
			 *	Set set=(Set)tft.getTFileType2s();
			 *	System.out.println(set.size());
			 */
			
		}catch (HibernateException e) {
			log.error(e);
			e.printStackTrace();
			throw new HibernateException(e);
		} finally {
			closeCurrentThreadSessions();
			
		}
		return tft;
	}///:~
	
	public List searchAll() throws HibernateException {
		List list = null;
		String sqlStr = "select tFileType from TFileType tFileType where tFileType.flag='0' ";
		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 + =
减小字号Ctrl + -
显示快捷键?