我希望在同一个数据库中有一个单独的持久化上下文,但不同的模式。我使用Eclipselink作为JPA实现,数据库是PostgreSQL。
数据库应包含2个架构:
--txDBS
\_data.scheme
\_security.scheme
请问,请指导我如何在persistence.xml中的一个DBS中为每个模式声明一个持久性单元?
现在我有:
的persistence.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<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_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="txPersistUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.target-database" value="PostgreSQL"/>
<property name="eclipselink.cache.shared.default" value="true"/>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
<property name="javax.persistence.jdbc.url"
value="jdbc:postgresql://localhost:5432/TxSolution?charSet=LATIN2"/>
<property name="javax.persistence.jdbc.user" value="txman"/>
<property name="javax.persistence.jdbc.password" value="txman"/>
<!-- EclipseLink should create the database schema automatically -->
<property name="eclipselink.ddl-generation" value="create-or-extend-tables"/>
<property name="eclipselink.ddl-generation.output-mode"
value="database"/>
</properties>
</persistence-unit>
</persistence>
所以我想这样做:
@Produces
@PicketLink
@PersistenceContext
private EntityManager dataEm(unitName = "data.scheme.unit");
@Produces
@PicketLink
@PersistenceContext
private EntityManager secEm(unitName = "security.scheme.unit");