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

📄 provincedaohibernate.java

📁 hibernatedemo
💻 JAVA
字号:
/**
 * Hibernate Demo
 * Copyright by cinc
 */
package dao.hibernate;

import dao.ProvinceDAO;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;

import java.util.Collection;
import java.util.List;
import java.util.ArrayList;

import bean.Province;
import bean.Province;

public class ProvinceDAOHibernate implements ProvinceDAO{
    public Collection listProvince() throws HibernateException {
        List list = null;
        Session s = HibernateSessionFactory.openSession();
        Transaction tx = null;
        try{
            tx = s.beginTransaction();
            list = s.find( "from Province as province" );
            tx.commit();
        }catch(HibernateException he){
            if ( tx!=null ){
                tx.rollback();
            }
            throw he;
        }finally{
            s.close();
        }
        return list;
    }

    public Province findById(long id) throws HibernateException {
        Province p = null;
        Session s = HibernateSessionFactory.openSession();
        Transaction tx = null;
        try{
            tx = s.beginTransaction();
            p = (Province) s.load( Province.class, new Long(id) );
            tx.commit();
        }catch(HibernateException he){
            if ( tx!=null ){
                tx.rollback();
            }
            throw he;
        }finally{
            s.close();
        }
        return p;
    }
}

⌨️ 快捷键说明

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