persistence.xml

配置如下

  <?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&amp;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>



查考资料如下::
http://www.haojii.com/2011/01/jpa-hibernate-persistence-and-mysql-connection-timeout/

你可能感兴趣的:(xml,Hibernate,mysql,jpa,ejb)