JPA - EclipseLink - How to configure the database schema name at run time


I implement a Web Application (JEE6, EJB WebProfile) that uses an Oracle DB. My Problem is, that I need to change the used Database Schema (name) without recompile/repackage the application. So what I want (this is only an idea, maybe someone has an better one), is to have some configuration (JNDI) within the Server, that specifics the Schema name. But how configure Eclipse Link to use an other schema name at runtime?


At the moment I use the orm.xml file to specify the Schema name. But the Application uses three different Schema names (one for development, one for integration test, and one for production), so I need to compile and package (maven) the application 3 times.

I have a JEE6 EJB WebProfile Application running on an Glassfish with using an Oracle DB and the Database Connection is handled by the Application Server and provieded to the Application via JNDI.

Does any body has an idea how to configure the database schema name at runtime.

You can use an EclipseLink SessionCustomizer.


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) {