SysML-v2-API-Services icon indicating copy to clipboard operation
SysML-v2-API-Services copied to clipboard

allow overriding of persistence properties with system properties

Open wucke13 opened this issue 2 years ago • 0 comments

See https://github.com/Systems-Modeling/SysML-v2-API-Services/pull/109/commits/809037cff1d6124e3ae1ca9811f5c16c63bf9eb3

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

wucke13 avatar Jan 29 '24 17:01 wucke13