当前位置: 首页 > 面试题库 >

Hibernate连接池

裴韬
2023-03-14
问题内容

我似乎无法hibernate使用c3p0进行连接池,它说

12:30:35,038  INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
12:30:35,038  INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 20

hibernate配置:

<hibernate-configuration>
  <session-factory>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/xxx?autoReconnect=true</property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.password">xxxx</property>
      <property name="show_sql">false</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <property name="hibernate.c3p0.min_size">5</property>
      <property name="hibernate.c3p0.max_size">200</property>
      <property name="hibernate.c3p0.max_statements">200</property>
      <property name="current_session_context_class">thread</property>
  </session-factory>
</hibernate-configuration>

问题答案:
        <!-- datasource config -->
        <property name="connection.url">jdbc:mysql://localhost:3306/db?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

        <property name="connection.username">user</property>
        <property name="connection.password">pass</property>

        <!-- c3p0 config http://www.hibernate.org/214.html -->
        <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>        
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.idle_test_period">60</property>
        <property name="hibernate.c3p0.min_size">1</property>
        <property name="hibernate.c3p0.max_size">2</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.timeout">0</property>
        <property name="hibernate.c3p0.acquireRetryAttempts">1</property>
        <property name="hibernate.c3p0.acquireRetryDelay">250</property>

        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.use_sql_comments">true</property>

        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
        <property name="hibernate.current_session_context_class">thread</property>

        ...

    </session-factory>
</hibernate-configuration>


 类似资料:
  • 以下代码: hibernate.cfg.xml: hibernateutil.java: 为了获得最好的帮助,当我尝试连接this Web服务时,请在Android Studio中查看my应用程序的日志: org.hibernate.exception.internal.standardsqlexceptionconverter.convert(standardsqlexceptionconver

  • 我有一个表,其中前5个是主类别,其他是子类别。 我需要获取前5个主类别的子类别,以便找到sql查询 查询正在联接同一个表本身。我得到的结果如下所示 后果 如何将SQL查询转换为HQL,并以标准json格式向用户返回上述图像之类的数据? 获取子类别 方法 谁能纠正我的错误,告诉我如何获得像上面的图像的结果?

  • 问题内容: 为什么在hibernate配置文件中为连接池设置10?size = 1是内置的size。为什么需要增加大小? 问题答案: 来自Hibernate API 文档。 但是,Hibernate自己的连接池算法非常初级。它旨在帮助您入门,不适合在生产系统中使用,甚至不用于性能测试。您应该使用第三方池来获得最佳性能和稳定性。只需将hibernate.connection.pool_size属性替

  • 另一个宽大处理--B: 这里要注意,实体A和B之间没有隐式关系,B表中的a_id是手工处理的,因此--关系类似于一对多(A-->B),但不是jpa-hibernate关系。而且,我的FullDto有A的所有属性和B的列表: 现在,我想从A的存储库接口中提取所有内容(A和B表一次完成),如下所示:

  • 问题内容: 我有一个空白的Spring MVC项目,并且已经使用Maven安装了Hibernate和PostgreSQL驱动程序。 我正在用完整的教程讲解如何显示PostgreSQL与Hibernate的连接。 这里有什么帮助吗? 问题答案: 这是posgresql的hibernate.cfg.xml,它将帮助您使用posgresql的基本hibernate配置。

  • 问题内容: 我正在尝试使用hibernate条件生成器连接4个表。 下面分别是这些表。 在这4个表中,我想为MySQL执行以下sql脚本: 那么,如何使用Hibernate CriteriaBuilder实现这一目标?请帮助… 预先感谢....... 问题答案: CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQue