0

I would like to have a separate persistence context within the same database but different schema. I'm using Eclipselink as JPA implementation and database is PostgreSQL.

The database should contain 2 schemas:

--txDBS
    \_data.scheme
    \_security.scheme

Can you, please, direct me how to declare one persistence unit per schema in one DBS in persistence.xml?

now I have:

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>

so I would like to do:

@Produces
​@PicketLink
​@PersistenceContext
​private EntityManager dataEm(unitName = "data.scheme.unit");

@Produces
​@PicketLink
​@PersistenceContext
​private EntityManager secEm(unitName = "security.scheme.unit");
greengold
  • 1,050
  • 3
  • 14
  • 29
  • asked too quickly.. answer here: [http://stackoverflow.com/a/4820666/1183729](http://stackoverflow.com/a/4820666/1183729) – greengold Oct 08 '15 at 11:57
  • The followup is much appreciated. I can re-open if you want to answer your own question with JPA-specific details. – Craig Ringer Oct 09 '15 at 04:46

0 Answers0