changeset 246:7a1bbd96cecd

Get id for LKommentarM manually from database.
author Raimund Renkert <rrenkert@intevation.de>
date Mon, 15 Jul 2013 15:36:54 +0200
parents 1963f002e4c0
children 8f27440a5f49
files src/main/java/de/intevation/lada/model/LKommentarMId.java src/main/java/de/intevation/lada/rest/LKommentarMService.java
diffstat 2 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/model/LKommentarMId.java	Mon Jul 15 13:22:55 2013 +0200
+++ b/src/main/java/de/intevation/lada/model/LKommentarMId.java	Mon Jul 15 15:36:54 2013 +0200
@@ -12,13 +12,13 @@
 public class LKommentarMId implements java.io.Serializable {
 
 	private String probeId;
-	private short messungsId;
+	private Integer messungsId;
 	private int KId;
 
 	public LKommentarMId() {
 	}
 
-	public LKommentarMId(String probeId, short messungsId, int KId) {
+	public LKommentarMId(String probeId, Integer messungsId, int KId) {
 		this.probeId = probeId;
 		this.messungsId = messungsId;
 		this.KId = KId;
@@ -34,11 +34,11 @@
 	}
 
 	@Column(name = "messungs_id", nullable = false)
-	public short getMessungsId() {
+	public Integer getMessungsId() {
 		return this.messungsId;
 	}
 
-	public void setMessungsId(short messungsId) {
+	public void setMessungsId(Integer messungsId) {
 		this.messungsId = messungsId;
 	}
 
--- a/src/main/java/de/intevation/lada/rest/LKommentarMService.java	Mon Jul 15 13:22:55 2013 +0200
+++ b/src/main/java/de/intevation/lada/rest/LKommentarMService.java	Mon Jul 15 15:36:54 2013 +0200
@@ -1,15 +1,20 @@
 package de.intevation.lada.rest;
 
+import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.List;
 
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
+import javax.persistence.Query;
 import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
 import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
@@ -21,6 +26,7 @@
 import de.intevation.lada.data.QueryBuilder;
 import de.intevation.lada.data.Repository;
 import de.intevation.lada.model.LKommentarM;
+import de.intevation.lada.model.LKommentarMId;
 
 /**
  * This class produces a RESTful service to read, write and update
@@ -132,6 +138,15 @@
         try {
             String probeId = kommentar.getProbeId();
             if (authentication.hasAccess(headers, probeId)) {
+                LKommentarMId id = new LKommentarMId();
+                Query q =
+                    repository.getEntityManager().createNativeQuery(
+                        "select nextval('kommentar_m_id_seq')");
+                BigInteger seqId = (BigInteger)q.getSingleResult();
+                id.setKId(seqId.intValue());
+                id.setMessungsId(kommentar.getMessungsId());
+                id.setProbeId(probeId);
+                kommentar.setId(id);
                 return repository.create(kommentar);
             }
             return new Response(false, 698, new ArrayList<LKommentarM>());
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)