File tree Expand file tree Collapse file tree
src/main/java/org/launchcode/codingevents/models Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package org .launchcode .codingevents .models ;
2+
3+ import jakarta .persistence .GeneratedValue ;
4+ import jakarta .persistence .Id ;
5+ import jakarta .persistence .MappedSuperclass ;
6+
7+ import java .util .Objects ;
8+ @ MappedSuperclass
9+ public abstract class AbstractEntity {
10+
11+ @ Id
12+ @ GeneratedValue
13+ private int id ;
14+
15+ public int getId () {
16+ return id ;
17+ }
18+
19+ @ Override
20+ public boolean equals (Object o ) {
21+ if (this == o ) return true ;
22+ if (o == null || getClass () != o .getClass ()) return false ;
23+ AbstractEntity entity = (AbstractEntity ) o ;
24+ return id == entity .id ;
25+ }
26+
27+ @ Override
28+ public int hashCode () {
29+ return Objects .hash (id );
30+ }
31+ }
Original file line number Diff line number Diff line change 1313 * Created by Chris Bay
1414 */
1515@ Entity
16- public class Event {
17-
18- @ Id
19- @ GeneratedValue
20- private int id ;
16+ public class Event extends AbstractEntity {
2117
2218 @ NotBlank (message = "Name is required" )
2319 @ Size (min = 3 , max = 50 , message = "Name must be between 3 and 50 characters" )
@@ -73,25 +69,12 @@ public void setType(EventType type) {
7369 this .type = type ;
7470 }
7571
76- public int getId () {
77- return id ;
78- }
72+
7973
8074 @ Override
8175 public String toString () {
8276 return name ;
8377 }
8478
85- @ Override
86- public boolean equals (Object o ) {
87- if (this == o ) return true ;
88- if (o == null || getClass () != o .getClass ()) return false ;
89- Event event = (Event ) o ;
90- return id == event .id ;
91- }
9279
93- @ Override
94- public int hashCode () {
95- return Objects .hash (id );
96- }
9780}
Original file line number Diff line number Diff line change 1111 * Created by Chris Bay
1212 */
1313@ Entity
14- public class EventCategory {
14+ public class EventCategory extends AbstractEntity {
1515
16- @ Id
17- @ GeneratedValue
18- private int id ;
1916
2017 @ Size (min =3 , message ="Name must be at least 3 characters long" )
2118 private String name ;
@@ -34,26 +31,12 @@ public void setName(String name) {
3431 this .name = name ;
3532 }
3633
37- public int getId () {
38- return id ;
39- }
4034
4135 @ Override
4236 public String toString () {
4337 return name ;
4438 }
4539
46- @ Override
47- public boolean equals (Object o ) {
48- if (this == o ) return true ;
49- if (o == null || getClass () != o .getClass ()) return false ;
50- EventCategory that = (EventCategory ) o ;
51- return id == that .id ;
52- }
5340
54- @ Override
55- public int hashCode () {
56- return Objects .hash (id );
57- }
5841}
5942
You can’t perform that action at this time.
0 commit comments