Skip to content

allow overriding of persistence properties with system properties #111

@wucke13

Description

@wucke13

See 809037c

Prior to this change, the only way to change the persistence settings
was to edit the persistence.xml. In case of a pre-build .jar, the
persistence.xml has to be contained in the .jar with the persistence
module [1], and can not be overridden. However, the current repo
hard-codes the DB connection details in the persistence.xml, which
makes it impossible to override the DB connection details for a fully
built .jar without changing that .jar file.

This change enable the overriding of the properties used for the JPA
EntityManagerFactory with system properties, so that DB connection
details can be altered without changing the .jar file.

diff --git a/app/jpa/manager/impl/HibernateManager.java b/app/jpa/manager/impl/HibernateManager.java
index 793d29c..bf8df83 100644
--- a/app/jpa/manager/impl/HibernateManager.java
+++ b/app/jpa/manager/impl/HibernateManager.java
@@ -38,7 +38,8 @@ public class HibernateManager implements JPAManager {
     private final EntityManagerFactory entityManagerFactory;
 
     public HibernateManager() {
-        entityManagerFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
+        entityManagerFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME,
+            System.getProperties());
     }
 
     @Override

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions