JPA - EclipseLink - How to configure Database Schema name at runtime JPA - EclipseLink - How to configure Database Schema name at runtime oracle oracle

JPA - EclipseLink - How to configure Database Schema name at runtime


You can use an EclipseLink SessionCustomizer.

package some.java.package;import org.eclipse.persistence.config.SessionCustomizer; import org.eclipse.persistence.sessions.Session; import org.eclipse.persistence.sessions.DatabaseLogin; public class MySessionCustomizer implements SessionCustomizer {  private String schema = "some_schema";  public MySessionCustomizer() {      schema = ... // read from property, jndi, etc.  }  public void customize(Session session) {       session.getLogin().setTableQualifier(schema);  } }


Configure JPA to use a datasource. Then you can configure different datasources for the applications in your app server.

Alternatively you can create an EntitymanagerFactory by passing a set of properties: http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManagerFactory.html#createEntityManager%28java.util.Map%29