• 构建hibernate


    package hanqi.dao;
    
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.Transaction;
    import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
    import org.hibernate.cfg.Configuration;
    import org.hibernate.service.ServiceRegistry;
    
    import hanqi.entity.Tbankcard;
    
    public class TbankcardDAO {
        
        Configuration cfg = null;
        ServiceRegistry sr = null;
         
        SessionFactory sf = null;
        Session se = null;
        Transaction tr= null;
        
        
        public TbankcardDAO()
        {
            //加载配置文件
            cfg  =  new Configuration().configure();
            
            //注册服务
            sr = new StandardServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
        }
        
        
        private void init()
        {
            //
            sf = cfg.buildSessionFactory(sr);
            se = sf.openSession();
            tr = se.beginTransaction();
        }
        
        
        private void destroy()
        {
            tr.commit();
            se.close();
            sf.close();
        }
        
        
        //单条查询
        public Tbankcard getTBbankcard(String cardid)
        {
            Tbankcard rtn = null;
            
            init();
            
            rtn = (Tbankcard)se.get(Tbankcard.class, cardid);
            
            
            destroy();
            
            
            return rtn;
            
        }
    
    }
  • 相关阅读:
    2019春季第五周作业
    第四周作业
    第三周作业编程总结
    第四周编程总结
    第三周编程总结
    2019春第一周作业编程总结
    我人生中对我影响深刻的三个老师
    秋季学习总结
    自我介绍
    2019春第10周作业
  • 原文地址:https://www.cnblogs.com/zs6666/p/6108461.html
Copyright © 2020-2023  润新知