gpt4 book ai didi

java - 验证 c3p0 使用 JPA 运行

转载 作者:太空宇宙 更新时间:2023-11-04 13:59:46 25 4
gpt4 key购买 nike

我使用 JPA 来持久化我的项目,并且对 hibernate 不太了解,但我遵循的大多数教程都发现使用 c3p0 和 hibernate 设置连接池。

这是我的 persistence.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="Cinemango308PU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>JPA.Ad</class>
<class>JPA.Photo</class>
<class>JPA.Theatre</class>
<class>JPA.Creditcard</class>
<class>JPA.Moviereview</class>
<class>JPA.Giftcard</class>
<class>JPA.Showtime</class>
<class>JPA.Ticket</class>
<class>JPA.Favoritetheatres</class>
<class>JPA.User</class>
<class>JPA.Actor</class>
<class>JPA.Movie</class>
<class>JPA.Theatrerewards</class>
<class>JPA.Payment</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:5432/cinemango>
<property name="javax.persistence.jdbc.user" value="xxxx"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value="xxxxxx"/>
<property name="javax.persistence.schema-generation.database.action" value="create"/>

<!-- Configuring Connection Pool -->
<property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />

<property name="hibernate.c3p0.max_size" value="5" />
<property name="hibernate.c3p0.min_size" value="0" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.idle_test_period" value="300" />
<property name="hibernate.c3p0.max_statements" value="0" />
<property name="hibernate.c3p0.timeout" value="100" />
</properties>
</persistence-unit>
</persistence>

如何测试连接池是否正常工作?我没有看到日志显示在我的输出中

最佳答案

请在此处找到日志记录配置 http://www.mchange.com/projects/c3p0/#configuring_logging

在那里您可以找到如何打开调试以查看是否发生池化。

关于java - 验证 c3p0 使用 JPA 运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29426149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com