خرید بک لینک

Vote count: 0

I am developing a JPA application which requires to be able to access different schemas on the same database (i.e. DB2/Oracle). I want all of my entities to be registered in the persistence.xml file (<class>) and be able to define which ones belong to certain schemas.

I know it is possible to use java aotations, however this is a product which will need the end user to configure that accordingly (hence why I want to be able to achieve this in an xml file).

Currently I have found an example like this:

orm.xml

  <?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
    version="2.0">
    <persistence-unit-metadata>
        <persistence-unit-defaults>
            <schema>SECURITY</schema>
        </persistence-unit-defaults>
    </persistence-unit-metadata>
</entity-mappings>

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
    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_2_0.xsd">
    <persistence-unit name="jpa.sample.plain">
        <mapping-file>custom-orm.xml</mapping-file>
        <class>com.reds.model.Role</class>
        <class>com.reds.model.User</class>
        <properties>
            <property name="javax.persistence.target-database" value="PostgreSQL" />
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://127.0.0.1:5432/security" />
            <property name="javax.persistence.jdbc.user" value="user" />
            <property name="javax.persistence.jdbc.password" value="password" />
            <!-- EclipseLink should create the database schema automatically -->
            <property name="eclipselink.ddl-generation" value="none" />
            <property name="eclipselink.weaving" value="false" />
            <!-- <property name="eclipselink.ddl-generation.output-mode"
                value="database" /> -->
            <property name="eclipselink.logging.level" value="INFO"/>
        </properties>     
    </persistence-unit>
</persistence>

In the above files, from my understanding the schema "SECURITY" is set on the persistence unit that includes the orm.xml mapping file (makes it the default which an aotation can change?). But this makes the schema be implicitly "SECURITY" for both classes listed in persistence.xml.

Contrary to the above I need:

  • A way to list the schema on a subset of classes in a persistence unit in an efficient way (unless if the only way is to do the entity mappings manually in the orm.xml which is something I wish to avoid and the end user would too)
  • Keep this away from vendor specific xml files or java implementations if possible (keep to JPA standard)
  • Side question: Would this allow a JPQL query to go through transparently for 2 entities with different schemas?

Details of project:

  • Hibeate 5.1, JPA 2.1
  • DB2/Oracle
asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 28 ارديبهشت 1395 ساعت: 3:37

صفحه بندی