From b7a9488e6d23d662b3afe8300867e5cb9ee93685 Mon Sep 17 00:00:00 2001 From: Gabriel Torelo <57268681+GabrielTorelo@users.noreply.github.com> Date: Fri, 14 Jul 2023 22:40:22 -0300 Subject: [PATCH 1/2] =?UTF-8?q?cria=20classe=20'BelongingPK'=20contendo=20?= =?UTF-8?q?refer=C3=AAncia=20ao=20GameID=20e=20GameListID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game_list/entities/BelongingPK.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/main/java/com/gabriel_torelo/game_list/entities/BelongingPK.java 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; + } +} From 8620bd50e78fa4f3f437b49af6e104137ffe6c33 Mon Sep 17 00:00:00 2001 From: Gabriel Torelo <57268681+GabrielTorelo@users.noreply.github.com> Date: Fri, 14 Jul 2023 22:41:12 -0300 Subject: [PATCH 2/2] cria classe 'Belonging' com ORM 'jakarta' --- .../game_list/entities/Belonging.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/com/gabriel_torelo/game_list/entities/Belonging.java 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; + } +}