From a3661f16dd1c6ff8b1c5cce79f0ac948990c190c Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 1 Aug 2021 10:41:22 +0200 Subject: KB66 LazychatMessage: Make LazychatReference into a @ManyToMany association. Change-Id: I6616c0e9dc6416abcc2e85c38924e5ca7045c062 --- .../mulkcms2/benki/lazychat/LazychatMessage.java | 18 +++++-- .../mulkcms2/benki/lazychat/LazychatReference.java | 33 ------------- .../benki/lazychat/LazychatReferencePK.java | 55 ---------------------- 3 files changed, 14 insertions(+), 92 deletions(-) delete mode 100644 src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReference.java delete mode 100644 src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReferencePK.java (limited to 'src/main/java/eu') diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java index f52e05a..63f4791 100644 --- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java +++ b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatMessage.java @@ -5,17 +5,27 @@ import java.util.Collection; import javax.annotation.CheckForNull; import javax.json.bind.annotation.JsonbTransient; import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.OneToMany; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; import javax.persistence.Table; @Entity @Table(name = "lazychat_messages", schema = "benki") public class LazychatMessage extends Post { - @OneToMany(mappedBy = "referrer", fetch = FetchType.LAZY) + @ManyToMany + @JoinTable( + name = "lazychat_references", + schema = "benki", + joinColumns = {@JoinColumn(name = "referrer")}, + inverseJoinColumns = {@JoinColumn(name = "referee")}) @JsonbTransient - public Collection references; + public Collection referees; + + @ManyToMany(mappedBy = "referees") + @JsonbTransient + public Collection referrers; @CheckForNull @Override diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReference.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReference.java deleted file mode 100644 index eecc23e..0000000 --- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReference.java +++ /dev/null @@ -1,33 +0,0 @@ -package eu.mulk.mulkcms2.benki.lazychat; - -import io.quarkus.hibernate.orm.panache.PanacheEntityBase; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Id; -import javax.persistence.IdClass; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "lazychat_references", schema = "benki") -@IdClass(LazychatReferencePK.class) -public class LazychatReference extends PanacheEntityBase { - - @Id - @Column(name = "referrer", nullable = false) - public int referrerId; - - @Id - @Column(name = "referee", nullable = false) - public int refereeId; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "referrer", referencedColumnName = "id", nullable = false) - public LazychatMessage referrer; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "referee", referencedColumnName = "id", nullable = false) - public LazychatMessage referee; -} diff --git a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReferencePK.java b/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReferencePK.java deleted file mode 100644 index 20ff71c..0000000 --- a/src/main/java/eu/mulk/mulkcms2/benki/lazychat/LazychatReferencePK.java +++ /dev/null @@ -1,55 +0,0 @@ -package eu.mulk.mulkcms2.benki.lazychat; - -import java.io.Serializable; -import javax.persistence.Column; -import javax.persistence.Id; - -public class LazychatReferencePK implements Serializable { - - private int referrerId; - private int refereeId; - - @Column(name = "referrer", nullable = false) - @Id - public int getReferrerId() { - return referrerId; - } - - public void setReferrerId(int referrerId) { - this.referrerId = referrerId; - } - - @Column(name = "referee", nullable = false) - @Id - public int getRefereeId() { - return refereeId; - } - - public void setRefereeId(int refereeId) { - this.refereeId = refereeId; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - LazychatReferencePK that = (LazychatReferencePK) o; - - if (referrerId != that.referrerId) { - return false; - } - return refereeId == that.refereeId; - } - - @Override - public int hashCode() { - int result = referrerId; - result = 31 * result + refereeId; - return result; - } -} -- cgit v1.2.3