2

I'm joining a project which uses

  • Tomcat 7
  • EclipseLink as JPA provider (could probably be changed)

This project is deployed to many different environments each with a different database connection. Currently all connection details for all databases are put together in the persistence.xml. So there are 10 entries like this:

<persistence-unit name="postgresql-system-xx" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>..</class>
    <class>..</class>
    <properties>
        <property name="eclipselink.logging.level"       value="FINE" />
        <property name="javax.persistence.jdbc.driver"   value="org.postgresql.Driver" />
        <property name="javax.persistence.jdbc.url"      value="jdbc:postgresql://localhost/db_xx" />
        <property name="javax.persistence.jdbc.user"     value="user_xx" />
        <property name="javax.persistence.jdbc.password" value="password_xx" />
        <property name="eclipselink.target-database"     value="PostgreSQL" />
    </properties>
</persistence-unit>

This is not sustainable.

My idea is to externalize the database connection details (all things which are here defined as properties). Then I could define these values server specific and I wouldn't have to maintain such a huge persistence.xml file.

Is there a way to externalize database connection details or another best practice?

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.