changeset 1034:61354a9fa58d schema-update

Make dynamic inserts on probe and messung objects to avoid 'not null'-constraint error.
author Raimund Renkert <raimund.renkert@intevation.de>
date Wed, 31 Aug 2016 15:50:54 +0200
parents 812e0cace5ba
children 4d95cc7f0a43
files src/main/java/de/intevation/lada/model/land/Messung.java src/main/java/de/intevation/lada/model/land/Probe.java src/main/java/de/intevation/lada/rest/MessungService.java src/main/java/de/intevation/lada/rest/ProbeService.java
diffstat 4 files changed, 26 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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
+@DynamicInsert(true)
 public class Messung implements Serializable {
     private static final long serialVersionUID = 1L;
 
--- 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
+@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;
     }
 
--- 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,
--- 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);
     }
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)