Skip to content

Commit 27e4262

Browse files
Merge pull request #9 from GabrielTorelo/feat/belongingClass
feat/belongingClass - OK
2 parents 21b2ff1 + 8620bd5 commit 27e4262

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.gabriel_torelo.game_list.entities;
2+
3+
import jakarta.persistence.EmbeddedId;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.Table;
6+
7+
@Entity
8+
@Table(name = "tb_belonging")
9+
public class Belonging {
10+
11+
@EmbeddedId
12+
private BelongingPK id = new BelongingPK();
13+
private Integer position;
14+
15+
public Belonging() {
16+
}
17+
18+
public Belonging(Game game, GameList list, Integer position) {
19+
id.setGame(game);
20+
id.setGameList(list);
21+
this.position = position;
22+
}
23+
24+
public BelongingPK getId() {
25+
return id;
26+
}
27+
28+
public void setId(BelongingPK id) {
29+
this.id = id;
30+
}
31+
32+
public Integer getPosition() {
33+
return position;
34+
}
35+
36+
public void setPosition(Integer position) {
37+
this.position = position;
38+
}
39+
40+
@Override
41+
public int hashCode() {
42+
final int prime = 31;
43+
int result = 1;
44+
result = prime * result + ((id == null) ? 0 : id.hashCode());
45+
return result;
46+
}
47+
48+
@Override
49+
public boolean equals(Object obj) {
50+
if (this == obj)
51+
return true;
52+
if (obj == null)
53+
return false;
54+
if (getClass() != obj.getClass())
55+
return false;
56+
Belonging other = (Belonging) obj;
57+
if (id == null) {
58+
if (other.id != null)
59+
return false;
60+
} else if (!id.equals(other.id))
61+
return false;
62+
return true;
63+
}
64+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.gabriel_torelo.game_list.entities;
2+
3+
import jakarta.persistence.Embeddable;
4+
import jakarta.persistence.JoinColumn;
5+
import jakarta.persistence.ManyToOne;
6+
7+
@Embeddable
8+
public class BelongingPK {
9+
10+
@ManyToOne
11+
@JoinColumn(name = "game_id")
12+
private Game game;
13+
14+
@ManyToOne
15+
@JoinColumn(name = "list_id")
16+
private GameList list;
17+
18+
public BelongingPK(){
19+
}
20+
21+
public BelongingPK(Game game, GameList gameList) {
22+
this.game = game;
23+
this.list = gameList;
24+
}
25+
26+
public Game getGame() {
27+
return game;
28+
}
29+
30+
public void setGame(Game game) {
31+
this.game = game;
32+
}
33+
34+
public GameList getGameList() {
35+
return list;
36+
}
37+
38+
public void setGameList(GameList gameList) {
39+
this.list = gameList;
40+
}
41+
42+
@Override
43+
public int hashCode() {
44+
final int prime = 31;
45+
int result = 1;
46+
result = prime * result + ((game == null) ? 0 : game.hashCode());
47+
result = prime * result + ((list == null) ? 0 : list.hashCode());
48+
return result;
49+
}
50+
51+
@Override
52+
public boolean equals(Object obj) {
53+
if (this == obj)
54+
return true;
55+
if (obj == null)
56+
return false;
57+
if (getClass() != obj.getClass())
58+
return false;
59+
BelongingPK other = (BelongingPK) obj;
60+
if (game == null) {
61+
if (other.game != null)
62+
return false;
63+
} else if (!game.equals(other.game))
64+
return false;
65+
if (list == null) {
66+
if (other.list != null)
67+
return false;
68+
} else if (!list.equals(other.list))
69+
return false;
70+
return true;
71+
}
72+
}

0 commit comments

Comments
 (0)