在JPA中使用连接池

Jas*_*per 5 java hibernate jpa connection-pooling persistence.xml

我有一个独立的JPA(Hibernate) - MySQL应用程序.

我的persistence.xml看起来像:

     <persistence-unit name="JPAProj" transaction-type="RESOURCE_LOCAL">
            <!-- Persistence provider -->
            <provider>
                org.hibernate.ejb.HibernatePersistence
            </provider>
          ....
          <properties>
                    <property name='hibernate.show_sql' value='true'/>
                    <property name='hibernate.format_sql' value='true'/>
                    <property name='hibernate.dialect' value='org.hibernate.dialect.MySQL5InnoDBDialect'/>
                    <property name='hibernate.hbm2ddl.auto' value='update'/>

                    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
                    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/classicmodels"/>
                    <property name="javax.persistence.jdbc.user" value="someuser"/>
                    <property name="javax.persistence.jdbc.password" value=""/>
           </properties>
     </persistence-unit>
Run Code Online (Sandbox Code Playgroud)

我想在此应用程序中使用连接池(比如Apache DBCP),我需要对persistence.xml进行哪些更改?

小智 5

您可以使用 c3p0 连接池进行休眠。检查此 url C3P0 配置