persistence.xml

本文详细介绍了如何配置JPA与Hibernate结合使用的XML文件,并针对MySQL数据库进行了特定设置,包括连接池参数、数据库方言等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

配置如下


<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
<persistence-unit name="sale" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="test"/>
<property name="hibernate.connection.password" value="test"/>
<property name="hibernate.connection.url" value="jdbc:mysql://192.168.1.206:3306/test?useUnicode=true&characterEncoding=UTF-8"/>
<property name="hibernate.max_fetch_depth" value="20"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.jdbc.fetch_size" value="18"/>
<property name="hibernate.jdbc.batch_size" value="10"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
<!-- hibernate的c3p0连接池配置-->
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
<!-- 最小连接数 -->
<property name="hibernate.c3p0.min_size" value="5"/>
<!-- 最大连接数 -->
<property name="hibernate.c3p0.max_size" value="30"/>
<!--最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="hibernate.c3p0.maxIdleTime" value="600"/>
<!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->
<property name="hibernate.c3p0.timeout" value="3000"/>
<!-- 最大的PreparedStatement的数量 -->
<property name="hibernate.c3p0.max_statements" value="50"/>
<!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒-->
<property name="hibernate.c3p0.idle_test_period" value="900"/>
<!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->
<property name="hibernate.c3p0.acquire_increment" value="3"/>
<property name="acquireRetryAttempts" value="30" />
<property name="acquireRetryDelay" value="1000" />
<property name="testConnectionOnCheckin" value="true" />
<!-- 是否每次都验证连接是否可用 -->
<property name="hibernate.c3p0.validate" value="true"/>
<property name="automaticTestTable" value="c3p0TestTable" />
<property name="hibernate.c3p0.preferredTestQuery" value="select 1;"/>
</properties>
</persistence-unit>
</persistence>



查考资料如下::
[url]http://www.haojii.com/2011/01/jpa-hibernate-persistence-and-mysql-connection-timeout/[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值