# HG changeset patch # User Raimund Renkert # Date 1373887375 -7200 # Node ID 1963f002e4c051f901a9f7592ecb803174593d07 # Parent f3e15ba7c3b735403f34593ffe7f7c6a104b0fb3 Use a sequence to generate the id and create an id object in service. diff -r f3e15ba7c3b7 -r 1963f002e4c0 src/main/java/de/intevation/lada/model/LMessung.java --- a/src/main/java/de/intevation/lada/model/LMessung.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/model/LMessung.java Mon Jul 15 13:22:55 2013 +0200 @@ -11,9 +11,12 @@ import javax.persistence.EmbeddedId; import javax.persistence.Entity; import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; @@ -23,9 +26,11 @@ */ @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; + private Integer messungsId; private String probeId; private String mmtId; private String nebenprobenNr; @@ -73,7 +78,16 @@ this.id = id; } - @Column(name = "probe_id", nullable = false, insertable = false, updatable = false) + @Column(name = "messungs_id", nullable = false, insertable = false, updatable = false) + public Integer getMessungsId() { + return messungsId; + } + + public void setMessungsId(Integer messungsId) { + this.messungsId = messungsId; + } + + @Column(name = "probe_id", nullable = false, insertable = false, updatable = false) public String getProbeId() { return this.probeId; } diff -r f3e15ba7c3b7 -r 1963f002e4c0 src/main/java/de/intevation/lada/model/LMessungId.java --- a/src/main/java/de/intevation/lada/model/LMessungId.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/model/LMessungId.java Mon Jul 15 13:22:55 2013 +0200 @@ -4,6 +4,8 @@ import javax.persistence.Column; import javax.persistence.Embeddable; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; /** * LMessungId generated by hbm2java @@ -32,6 +34,7 @@ } @Column(name = "messungs_id", nullable = false) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "MESSUNG_ID_STORE") public short getMessungsId() { return this.messungsId; } diff -r f3e15ba7c3b7 -r 1963f002e4c0 src/main/java/de/intevation/lada/model/LMesswertId.java --- a/src/main/java/de/intevation/lada/model/LMesswertId.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/model/LMesswertId.java Mon Jul 15 13:22:55 2013 +0200 @@ -12,13 +12,13 @@ public class LMesswertId implements java.io.Serializable { private String probeId; - private short messungsId; + private Integer messungsId; private int messgroesseId; public LMesswertId() { } - public LMesswertId(String probeId, short messungsId, int messgroesseId) { + public LMesswertId(String probeId, Integer messungsId, int messgroesseId) { this.probeId = probeId; this.messungsId = messungsId; this.messgroesseId = messgroesseId; @@ -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; } diff -r f3e15ba7c3b7 -r 1963f002e4c0 src/main/java/de/intevation/lada/rest/LMessungService.java --- a/src/main/java/de/intevation/lada/rest/LMessungService.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LMessungService.java Mon Jul 15 13:22:55 2013 +0200 @@ -22,6 +22,7 @@ import de.intevation.lada.data.QueryBuilder; import de.intevation.lada.data.Repository; import de.intevation.lada.model.LMessung; +import de.intevation.lada.model.LMessungId; /** * This class produces a RESTful service to read, write and update @@ -133,6 +134,9 @@ try { String probeId = messung.getProbeId(); if (authentication.hasAccess(headers, probeId)) { + LMessungId id = new LMessungId(); + id.setProbeId(probeId); + messung.setId(id); return repository.create(messung); } return new Response(false, 698, new ArrayList()); diff -r f3e15ba7c3b7 -r 1963f002e4c0 src/main/java/de/intevation/lada/rest/LMesswertService.java --- a/src/main/java/de/intevation/lada/rest/LMesswertService.java Mon Jul 15 13:22:00 2013 +0200 +++ b/src/main/java/de/intevation/lada/rest/LMesswertService.java Mon Jul 15 13:22:55 2013 +0200 @@ -23,6 +23,7 @@ import de.intevation.lada.data.Repository; import de.intevation.lada.model.LMessung; import de.intevation.lada.model.LMesswert; +import de.intevation.lada.model.LMesswertId; /** * This class produces a RESTful service to read, write and update @@ -141,6 +142,11 @@ Integer messungsId = messwert.getMessungsId(); if (authentication.hasAccess(headers, probeId) && !isReadOnly(probeId, messungsId)) { + LMesswertId id = new LMesswertId(); + id.setMessgroesseId(messwert.getMessgroesseId()); + id.setMessungsId(messungsId); + id.setProbeId(probeId); + messwert.setId(id); return repository.create(messwert); } return new Response(false, 698, new ArrayList());