怎样在spring+jpa中配置多个persistence-unit

joygarden 2010-08-24 12:02:26
比如persistence.xml中unit1 和unit2 在spring配置文件中应该怎样配置:

<?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="unit1"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class></class>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.driver_class"
value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.url"
value="jdbc:oracle:thin:@xxx.xxx.xxxx.xxxx:1521:xxx" />
<property name="hibernate.connection.username"
value="xxxx" />
<property name="hibernate.connection.password"
value="xxxx" />
</properties>
</persistence-unit>

<persistence-unit name="unit2"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>

<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.driver_class"
value="oracle.jdbc.driver.OracleDriver" />

<property name="hibernate.connection.url"
value="jdbc:oracle:thin:@xxx.xxx.xxxx.xxxx:1521:xxx" />
<property name="hibernate.connection.username"
value="xxxx" />
<property name="hibernate.connection.password"
value="xxxx" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.c3p0.timeout" value="50000" />
<property name="hibernate.c3p0.idle_test_period"
value="300" />
<property name="hibernate.hbm2ddl.auto" value="true" />
<property name="hibernate.default_schema" value="xxxx" />
</properties>
</persistence-unit>

</persistence>



...全文
214 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧