【问题标题】:Is Hibernate also use connection pool as JDBC?Hibernate 是否也使用连接池作为 JDBC?
【发布时间】:2014-12-05 08:48:10
【问题描述】:

我的应用程序使用 JBOSS 7.1 Web 服务器。我配置了 JBOSS 连接池并将其用于 JDBC 连接。我也在我的应用程序中使用休眠。我想知道hibernate是否也使用这个连接池或者我需要为hibernate配置其他连接池(例如c3p0)?

【问题讨论】:

  • 如果您使用 JNDI 来配置 Hibernate,那么是的,它将使用 Jboss 连接池。

标签: java hibernate jdbc jboss7.x connection-pooling


【解决方案1】:

C3P0 连接池

 <property name="hibernate.c3p0.min_size">5</property>
  <property name="hibernate.c3p0.max_size">20</property>
  <property name="hibernate.c3p0.timeout">300</property>
  <property name="hibernate.c3p0.max_statements">50</property>
  <property name="hibernate.c3p0.idle_test_period">3000</property>

hibernate.c3p0.min_size – 池中的最小 JDBC 连接数。休眠默认值:1 hibernate.c3p0.max_size – 池中的最大 JDBC 连接数。休眠默认值:100 hibernate.c3p0.timeout – 从池中删除空闲连接时(以秒为单位)。休眠默认值:0,永不过期。 hibernate.c3p0.max_statements – 准备好的语句数将被缓存。提高性能。休眠默认值: 0 ,禁用缓存。 hibernate.c3p0.idle_test_period – 在自动验证连接之前的空闲时间(以秒为单位)。休眠默认值:0

http://docs.jboss.org/hibernate/orm/4.2/devguide/en-US/html/ch01.html

【讨论】:

    【解决方案2】:

    hibernate.cfg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
     <session-factory>
      <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
      <property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:schema</property>
      <property name="hibernate.connection.username">user</property>
      <property name="hibernate.connection.password">password</property>
      <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
      <property name="hibernate.default_schema">schema</property>
      <property name="show_sql">true</property>
    
      <property name="hibernate.c3p0.min_size">5</property>
      <property name="hibernate.c3p0.max_size">20</property>
      <property name="hibernate.c3p0.timeout">300</property>
      <property name="hibernate.c3p0.max_statements">50</property>
      <property name="hibernate.c3p0.idle_test_period">3000</property>
    

    hibernate.c3p0.min_size – Minimum number of JDBC connections in the pool. Hibernate default: 1
    hibernate.c3p0.max_size – Maximum number of JDBC connections in the pool. Hibernate default: 100
    hibernate.c3p0.timeout – When an idle connection is removed from the pool (in second). Hibernate default: 0, never expire.
    hibernate.c3p0.max_statements – Number of prepared statements will be cached. Increase performance. Hibernate default: 0 , caching is disable.
    hibernate.c3p0.idle_test_period – idle time in seconds before a connection is automatically validated. Hibernate default: 0
    

    更多详情请参考link

    【讨论】:

      猜你喜欢
      • 2022-08-09
      • 1970-01-01
      • 2011-05-05
      • 2016-07-06
      • 2011-03-06
      • 2013-10-12
      • 2010-11-30
      • 1970-01-01
      • 2011-10-10
      相关资源
      最近更新 更多