Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/main/java/com/gabriel_torelo/game_list/entities/Belonging.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}