[AB-161] fixed composite foreign keys for multiple tables

This commit is contained in:
Sheldan
2020-11-22 18:38:51 +01:00
parent 1d9f2595db
commit b05a834b59
12 changed files with 36 additions and 60 deletions

View File

@@ -1,5 +1,6 @@
package dev.sheldan.abstracto.utility.models.database;
import dev.sheldan.abstracto.core.models.ServerSpecificId;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
@@ -10,7 +11,6 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
import javax.persistence.*;
import java.io.Serializable;
import java.time.Instant;
import java.util.Objects;
@Entity
@Table(name="suggestion")
@@ -25,9 +25,9 @@ import java.util.Objects;
public class Suggestion implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
private Long id;
@EmbeddedId
private ServerSpecificId suggestionId;
@Getter
@ManyToOne
@@ -43,9 +43,9 @@ public class Suggestion implements Serializable {
@JoinColumn(name = "channelId")
private AChannel channel;
@Getter
@ManyToOne
@JoinColumn(name = "serverId")
@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
@MapsId("serverId")
@JoinColumn(name = "server_id", referencedColumnName = "id", nullable = false)
private AServer server;
@Getter
@@ -71,22 +71,4 @@ public class Suggestion implements Serializable {
this.updated = Instant.now();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Suggestion that = (Suggestion) o;
return Objects.equals(id, that.id) &&
Objects.equals(suggester, that.suggester) &&
Objects.equals(messageId, that.messageId) &&
Objects.equals(channel, that.channel) &&
Objects.equals(server, that.server) &&
Objects.equals(suggestionDate, that.suggestionDate) &&
state == that.state;
}
@Override
public int hashCode() {
return Objects.hash(id, suggester, messageId, channel, server, suggestionDate, state);
}
}