I am getting a little of challenge with a particular problem using JPA/Spring:

How do i dynamically assign a schema for an entity?

We've TABLE1 that goes to schema AD and TABLE2 that's under BD.

@Entity
@Table(name = "TABLE1", schema="S1D")
...

@Entity
@Table(name = "TABLE2", schema="S2D")
...

The schemas might not be hardcoded within an annotation attribute because it is dependent around the atmosphere (Dev/Acc/Prd). (In acceptance the schemas are S1A and S2A)

How do i accomplish this? Can you really specify some type of placeholders such as this:

@Entity
@Table(name = "TABLE1", schema="${schema1}")
...

@Entity
@Table(name = "TABLE2", schema="${schema2}")
...

to ensure that schemas are changed with different property file dwelling within the atmosphere?

Cheers

One factor that you can do knowing at deployment would be to have 2 orm.xml files. One for schema1 and something for schema2 after which within the persistence.xml you've 2 persistence-models defined. Putting annotations is definitely an anti-pattern if requiring to alter such things as schema

You might have two DataSource terms (one for every schema) inside your context.xml and define two persistence models by using this datasources. The context.xml may then differ around the appservers from the different conditions.

Annotation arguments need to be final and may therefore 't be transformed at runtime.

N

I'd exactly the same problem I solved by using a persistence.xml by which I make reference to the appropriate orm.xml files within I declared the db shema

<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_2_0.xsd"
version="2.0" >
<persistence-unit name="schemaOne">
    . . .
    <mapping-file>ormOne.xml</mapping-file>
    . . .
</persistence-unit>

<persistence-unit name="schemaTwo">
. . .
<mapping-file>ormTwo.xml</mapping-file>
. . .
 </persistence-unit>
</persistence>

you can now produce a EntityManagerFactory for the special schema

EntityManagerFactory emf=Persistence.createEntityManagerFactory("schemaOne");