-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathAbstractEntity.java
More file actions
40 lines (32 loc) · 1.04 KB
/
AbstractEntity.java
File metadata and controls
40 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package org.launchcode.codingevents.models;
import org.springframework.data.annotation.Id;
import javax.persistence.GeneratedValue;
import javax.persistence.MappedSuperclass;
import java.util.Objects;
@MappedSuperclass
public abstract class AbstractEntity {
@Id
@GeneratedValue
public int id;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public boolean equals(Object o) {
// Check if both references point to the same object in memory
if (this == o) return true;
// Check if the object being compared is null or is not of the same class
if (o == null || getClass() != o.getClass()) return false;
// Cast the object to AbstractEntity since we're comparing ids
AbstractEntity entity = (AbstractEntity) o;
// Compare the id of the current object with the id of the object being compared
return id == entity.id;
}
@Override
public int hashCode() {
return Objects.hash(id);
}
}