[Lada-commits] [PATCH 4 of 6] Make dynamic inserts on probe and messung objects to avoid 'not null'-constraint error

Wald Commits scm-commit at wald.intevation.org
Wed Aug 31 16:24:12 CEST 2016


# HG changeset patch
# User Raimund Renkert <raimund.renkert at intevation.de>
# Date 1472651454 -7200
# Branch schema-update
# Node ID 61354a9fa58df136d2dd5e2bd90c1e569b68a201
# Parent  812e0cace5baf680e08f1223a892af3919d69b86
Make dynamic inserts on probe and messung objects to avoid 'not null'-constraint error.

diff -r 812e0cace5ba -r 61354a9fa58d src/main/java/de/intevation/lada/model/land/Messung.java
--- a/src/main/java/de/intevation/lada/model/land/Messung.java	Wed Aug 31 15:49:40 2016 +0200
+++ b/src/main/java/de/intevation/lada/model/land/Messung.java	Wed Aug 31 15:50:54 2016 +0200
@@ -12,12 +12,18 @@
 import javax.persistence.OneToOne;
 import javax.persistence.Transient;
 
+import org.hibernate.annotations.DynamicInsert;
+
 
 /**
  * The persistent class for the messung database table.
  * 
  */
+// The DynamicInsert Annotation has the effect, that the persisted object still
+// has all the "null"-values. There is no reloading after the persistence
+// process!
 @Entity
+ at DynamicInsert(true)
 public class Messung implements Serializable {
     private static final long serialVersionUID = 1L;
 
diff -r 812e0cace5ba -r 61354a9fa58d src/main/java/de/intevation/lada/model/land/Probe.java
--- a/src/main/java/de/intevation/lada/model/land/Probe.java	Wed Aug 31 15:49:40 2016 +0200
+++ b/src/main/java/de/intevation/lada/model/land/Probe.java	Wed Aug 31 15:50:54 2016 +0200
@@ -10,12 +10,18 @@
 import javax.persistence.Id;
 import javax.persistence.Transient;
 
+import org.hibernate.annotations.DynamicInsert;
+
 
 /**
  * The persistent class for the probe database table.
  * 
  */
+// The DynamicInsert Annotation has the effect, that the persisted object still
+// has all the "null"-values. There is no reloading after the persistence
+// process!
 @Entity
+ at DynamicInsert(true)
 public class Probe implements Serializable {
     private static final long serialVersionUID = 1L;
 
@@ -24,7 +30,7 @@
     private Integer id;
 
     @Column(name="ba_id")
-    private String baId;
+    private Integer baId;
 
     @Column(name="datenbasis_id")
     private Integer datenbasisId;
@@ -103,11 +109,11 @@
         this.id = id;
     }
 
-    public String getBaId() {
+    public Integer getBaId() {
         return this.baId;
     }
 
-    public void setBaId(String baId) {
+    public void setBaId(Integer baId) {
         this.baId = baId;
     }
 
diff -r 812e0cace5ba -r 61354a9fa58d src/main/java/de/intevation/lada/rest/MessungService.java
--- a/src/main/java/de/intevation/lada/rest/MessungService.java	Wed Aug 31 15:49:40 2016 +0200
+++ b/src/main/java/de/intevation/lada/rest/MessungService.java	Wed Aug 31 15:50:54 2016 +0200
@@ -293,6 +293,7 @@
         /* Persist the new messung object*/
         Response response = repository.create(messung, "land");
         Messung ret = (Messung)response.getData();
+        Messung refreshed = repository.getByIdPlain(Messung.class, ret.getId(), "land");
         if(violation.hasWarnings()) {
             response.setWarnings(violation.getWarnings());
         }
@@ -305,10 +306,10 @@
         status.setMstId(probe.getMstId());
         status.setStatusKombi(1);
         repository.create(status, "land");
-        ret.setStatus(status.getId());
-        repository.update(ret, "land");
+        refreshed.setStatus(status.getId());
+        repository.update(refreshed, "land");
         Response updated=
-            repository.getById(Messung.class, ret.getId(), "land");
+            repository.getById(Messung.class, refreshed.getId(), "land");
 
         return authorization.filter(
             request,
diff -r 812e0cace5ba -r 61354a9fa58d src/main/java/de/intevation/lada/rest/ProbeService.java
--- a/src/main/java/de/intevation/lada/rest/ProbeService.java	Wed Aug 31 15:49:40 2016 +0200
+++ b/src/main/java/de/intevation/lada/rest/ProbeService.java	Wed Aug 31 15:50:54 2016 +0200
@@ -325,13 +325,18 @@
         /* Persist the new probe object*/
         Response newProbe = repository.create(probe, "land");
         Probe ret = (Probe)newProbe.getData();
+        // Refreshing the probe object is necessary because probe objects use
+        // dynamic-insert, meaning null values are not written to the db and not
+        // updated after insert.
+        Response refreshed =
+            repository.getById(Probe.class, ret.getId(), "land");
         /* Create and persist a new probe translation object*/
         if(violation.hasWarnings()) {
-            newProbe.setWarnings(violation.getWarnings());
+            refreshed.setWarnings(violation.getWarnings());
         }
         return authorization.filter(
             request,
-            newProbe,
+            refreshed,
             Probe.class);
     }
 


More information about the Lada-commits mailing list