Mercurial > lada > lada-server
changeset 248:04b5f401e871
Get the sequence id for LMessung manually from database.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Mon, 15 Jul 2013 15:39:39 +0200 |
parents | 8f27440a5f49 |
children | 2dbe200b73f5 |
files | src/main/java/de/intevation/lada/model/LMessung.java src/main/java/de/intevation/lada/model/LMessungId.java src/main/java/de/intevation/lada/rest/LMessungService.java |
diffstat | 3 files changed, 10 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/de/intevation/lada/model/LMessung.java Mon Jul 15 15:38:46 2013 +0200 +++ b/src/main/java/de/intevation/lada/model/LMessung.java Mon Jul 15 15:39:39 2013 +0200 @@ -26,7 +26,6 @@ */ @Entity @Table(name = "l_messung", schema = "public") -@SequenceGenerator(name = "MESSUNG_ID_STORE", sequenceName = "messung_id_seq") public class LMessung implements java.io.Serializable { private LMessungId id;
--- a/src/main/java/de/intevation/lada/model/LMessungId.java Mon Jul 15 15:38:46 2013 +0200 +++ b/src/main/java/de/intevation/lada/model/LMessungId.java Mon Jul 15 15:39:39 2013 +0200 @@ -14,12 +14,12 @@ public class LMessungId implements java.io.Serializable { private String probeId; - private short messungsId; + private Integer messungsId; public LMessungId() { } - public LMessungId(String probeId, short messungsId) { + public LMessungId(String probeId, Integer messungsId) { this.probeId = probeId; this.messungsId = messungsId; } @@ -34,12 +34,11 @@ } @Column(name = "messungs_id", nullable = false) - @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MESSUNG_ID_STORE") - 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/LMessungService.java Mon Jul 15 15:38:46 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LMessungService.java Mon Jul 15 15:39:39 2013 +0200 @@ -1,11 +1,13 @@ 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.GET; import javax.ws.rs.POST; @@ -134,8 +136,12 @@ try { String probeId = messung.getProbeId(); if (authentication.hasAccess(headers, probeId)) { + Query q = repository.getEntityManager().createNativeQuery( + "select nextval('messung_id_seq')"); + BigInteger seqId = (BigInteger)q.getSingleResult(); LMessungId id = new LMessungId(); id.setProbeId(probeId); + id.setMessungsId(seqId.intValue()); messung.setId(id); return repository.create(messung); }