diff --git a/src/main/java/com/gabriel_torelo/game_list/entities/Belonging.java b/src/main/java/com/gabriel_torelo/game_list/entities/Belonging.java new file mode 100644 index 0000000..581ea33 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/entities/Belonging.java @@ -0,0 +1,64 @@ +package com.gabriel_torelo.game_list.entities; + +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; + +@Entity +@Table(name = "tb_belonging") +public class Belonging { + + @EmbeddedId + private BelongingPK id = new BelongingPK(); + private Integer position; + + public Belonging() { + } + + public Belonging(Game game, GameList list, Integer position) { + id.setGame(game); + id.setGameList(list); + this.position = position; + } + + public BelongingPK getId() { + return id; + } + + public void setId(BelongingPK id) { + this.id = id; + } + + public Integer getPosition() { + return position; + } + + public void setPosition(Integer position) { + this.position = position; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Belonging other = (Belonging) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + return true; + } +} diff --git a/src/main/java/com/gabriel_torelo/game_list/entities/BelongingPK.java b/src/main/java/com/gabriel_torelo/game_list/entities/BelongingPK.java new file mode 100644 index 0000000..d261a86 --- /dev/null +++ b/src/main/java/com/gabriel_torelo/game_list/entities/BelongingPK.java @@ -0,0 +1,72 @@ +package com.gabriel_torelo.game_list.entities; + +import jakarta.persistence.Embeddable; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; + +@Embeddable +public class BelongingPK { + + @ManyToOne + @JoinColumn(name = "game_id") + private Game game; + + @ManyToOne + @JoinColumn(name = "list_id") + private GameList list; + + public BelongingPK(){ + } + + public BelongingPK(Game game, GameList gameList) { + this.game = game; + this.list = gameList; + } + + public Game getGame() { + return game; + } + + public void setGame(Game game) { + this.game = game; + } + + public GameList getGameList() { + return list; + } + + public void setGameList(GameList gameList) { + this.list = gameList; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((game == null) ? 0 : game.hashCode()); + result = prime * result + ((list == null) ? 0 : list.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BelongingPK other = (BelongingPK) obj; + if (game == null) { + if (other.game != null) + return false; + } else if (!game.equals(other.game)) + return false; + if (list == null) { + if (other.list != null) + return false; + } else if (!list.equals(other.list)) + return false; + return true; + } +}