jpa的hibernate实现与eclipselnk实现的配置

classpath(如:src)下面META-INF/persistence.xml

以下示例:

eclipselink的

jpa的hibernate实现与eclipselnk实现的配置
<?xml version="1.0" encoding="UTF-8"?>
<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="xxxpu" transaction-type="RESOURCE_LOCAL">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
      <class>cn.com.xx.jpa.po.xxx</class>  
      <class>cn.com.xx.jpa.po.yyy</class>  
  <properties>
      <property name="javax.persistence.jdbc.driver"   value="oracle.jdbc.driver.OracleDriver" /> 
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@192.168.1.3:1521:ORCL" /> <property name="javax.persistence.jdbc.user" value="xx" /> <property name="javax.persistence.jdbc.password" value="yy" /> </properties> </persistence-unit> </persistence>
jpa的hibernate实现与eclipselnk实现的配置

hibernate + proxxol的

jpa的hibernate实现与eclipselnk实现的配置
<?xml version="1.0" encoding="UTF-8"?>
<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="xxxpu" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>cn.com.xx.jpa.po.xxx</class>  
     
      <class>cn.com.xx.jpa.po.yyy</class> <properties> <property name="hibernate.connection.provider_class" value="org.hibernate.connection.ProxoolConnectionProvider" /> <property name="hibernate.proxool.pool_alias" value="xxx_xx" /> <property name="hibernate.proxool.xml" value="proxool.xml" /> <property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" /> <property name="hibernate.hbm2ddl.auto" value="none" /> <property name="hibernate.show_sql" value="true" /> </properties> </persistence-unit> </persistence>
jpa的hibernate实现与eclipselnk实现的配置
jpa的hibernate实现与eclipselnk实现的配置
<?xml version="1.0" encoding="UTF-8"?>

<something-else-entirely>
    <proxool>
    <alias>xxx_xx</alias>
    <driver-url><![CDATA[jdbc:oracle:thin:@192.168.1.3:1521:ORCL]]></driver-url>
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <driver-properties>
      <property name="user" value="xx"/>
      <property name="password" value="yy"/>
    </driver-properties>
    <minimum-connection-count>1</minimum-connection-count> 
    <maximum-connection-count>10</maximum-connection-count>
    <test-before-use>true</test-before-use>
    <house-keeping-test-sql>select 1 from dual</house-keeping-test-sql>
    <house-keeping-sleep-time>900000</house-keeping-sleep-time>
    <maximum-active-time>3600000</maximum-active-time>
  </proxool>
</something-else-entirely>
jpa的hibernate实现与eclipselnk实现的配置


在spring配置文件中配置jpa

jpa的hibernate实现与eclipselnk实现的配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-2.5.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

<!--就是这个了        --> <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"> <property name="persistenceUnitName" value="xxxpu" /> </bean>

<!--注解扫描--> <context:component-scan base-package="cn.com.xxx" > </context:component-scan> <!--事物(可以使用其他方式)        --> <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <property name="entityManagerFactory" ref="entityManagerFactory" /> </bean> <!--加@Transactional注解使用事物        --> <tx:annotation-driven transaction-manager="transactionManager" />
</beans>
jpa的hibernate实现与eclipselnk实现的配置

jpa的hibernate实现与eclipselnk实现的配置

上一篇:sublime入门文章


下一篇:头发怎么抠图?简单快速的ps美女头发抠图教程