请教hibernate每一次select查询都需要开一个新的数据库连接吗?hibernate是怎样来管理数据库连接的?

解决方案 »

  1.   

    楼主参考一下这个博客:
    http://blog.chinaunix.net/u2/76927/showart_1726634.html这边博客讲了数据库连接池和Hibernate中对于连接池的使用应该对你有帮助
      

  2.   

    hibernate实现了JNDI JDBC JTA
    hibernate每一次select查询并不需要每次连接数据库  使用Hibernate 对数据库操作可以写一个工具类
    public class HibernateUtils { private static SessionFactory factory;

    static {
    try {
    Configuration cfg = new Configuration().configure();
    factory = cfg.buildSessionFactory();
    }catch(Exception e) {
    e.printStackTrace();
    }
    }

    public static SessionFactory getSessionFactory() {
    return factory;
    }

    public static Session getSession() {
    return factory.openSession();
    }

    public static void closeSession(Session session) {
    if (session != null) {
    if (session.isOpen()) {
    session.close();
    }
    }
    }
    }对数据库增删改查的时候 可以调用这个类。
    详细可去下载hibernate中文帮助文档  http://download.csdn.net/source/1018585