Embed property in JPA orm.xml?

We split our baseline (for the simultaneous development of versions 1.0 and 2.0). Instead of supporting two separate databases (and hardware), we are exploring other alternatives. We would like to be able to use the same database instance and have duplicate copies of tables / data in two different schemes:

1.0: SCHEMA_1
2.0: SCHEMA_2

The JPA orm.xml file has a property that specifies the schema:

<schema>SCHEMA_1</schema>

My question is whether it is possible to enter a property instead of a hard coded schema name (and how).

For example, if we have a .properties file with the following:

schema.name=SCHEMA_1

Can we then use schema.name in the orm.xml file as follows:

<SCHEMA>schema.name</SCHEMA>

Thanks for any help! Other alternatives for creating a dynamic circuit are also welcome.

+3
3

velocity-maven .

orm.xml:

<schema>${schemaName}</schema>

pom:

     <plugin>
        <groupId>net.rumati.maven.plugins</groupId>
        <artifactId>velocity-maven-plugin</artifactId>
        <version>0.1.1</version>
        <executions>
           <execution>
              <id>replaceSchema</id>
              <phase>generate-sources</phase>
              <goals>
                 <goal>velocity</goal>
              </goals>
           </execution>
        </executions>
        <configuration>
          <template>${basedir}/src/main/resources/hibernate/template/orm.xml</template>
          <properties>
             <schemaName>${r1Schema}</schemaName>
          </properties>
          <outputFile>${basedir}/src/main/resources/hibernate/orm.xml</outputFile>
        </configuration>
     </plugin>
+2

JPA orm.xml.

EclipseLink SessionCustomizer, EclipseLink ,

session.getLogin().setTableQualifier("SCHEMA_1");
+3

I ran into the exact problem. Instead of creating orm.xml in the project, leave it outside the artifact assembly. Then at runtime, put it on the application class path so that it raises:

<persistence-unit-metadata>
    <persistence-unit-defaults>
        <schema>MySchemaThatsBeenDeterminedAtRuntime</schema>
    </persistence-unit-defaults>
</persistence-unit-metadata>

Each application instance can have its own orm.xml and point to a different scheme.

+2
source

All Articles