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+
6+ import java .util .Objects ;
7+
8+ public abstract class AbstractEntity {
9+
10+ @ Id
11+ @ GeneratedValue
12+ @ MappedSuperclass
13+ protected 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 that = (AbstractEntity ) o ;
24+ return id == that .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 1010import java .util .Objects ;
1111
1212@ Entity
13- public class Event {
14-
15- @ Id
16- @ GeneratedValue
17- private int id ;
18-
13+ public class Event extends AbstractEntity {
1914 @ NotBlank (message = "Name is required" )
2015 @ Size (min = 3 , max = 50 , message = "Name must be between 3 and 50 characters" )
2116 private String name ;
@@ -83,8 +78,8 @@ public String toString() {
8378 public boolean equals (Object o ) {
8479 if (this == o ) return true ;
8580 if (o == null || getClass () != o .getClass ()) return false ;
86- Event event = (Event ) o ;
87- return id == event .id ;
81+ AbstractEntity that = (AbstractEntity ) o ; // Fix: Cast to AbstractEntity
82+ return id == that .id ;
8883 }
8984
9085 @ Override
Original file line number Diff line number Diff line change 1+ package org .launchcode .codingevents .models ;
2+
3+ import jakarta .persistence .Entity ;
4+ import jakarta .validation .constraints .Size ;
5+
6+ @ Entity
7+ public class EventCategory extends AbstractEntity {
8+
9+ @ Size (min = 3 , message = "Name must be at least 3 characters long" )
10+ private String name ;
11+
12+ public EventCategory (@ Size (min = 3 , message = "Name must be at least 3 characters long" ) String name ) {
13+ this .name = name ;
14+ }
15+
16+ public EventCategory () {}
17+
18+ public String getName () {
19+ return name ;
20+ }
21+
22+ public void setName (String name ) {
23+ this .name = name ;
24+ }
25+
26+ @ Override
27+ public String toString () {
28+ return name ;
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments