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

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

以下示例:

eclipselink的

<?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>

hibernate + proxxol的

<?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>
<?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>


在spring配置文件中配置jpa

<?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>

 

转载于:https://www.cnblogs.com/ooi-/p/3514139.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值