Skip to content

Commit c0c1515

Browse files
committed
so frustrating!
1 parent 56e8db1 commit c0c1515

4 files changed

Lines changed: 36 additions & 50 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
9+
@MappedSuperclass
10+
public class AbstractEntity {
11+
@Id
12+
@GeneratedValue
13+
private int id;
14+
15+
public int getId() {
16+
return id;
17+
}
18+
@Override
19+
public boolean equals(Object o) {
20+
if (this == o) return true;
21+
if (o == null || getClass() != o.getClass()) return false;
22+
AbstractEntity entity = (AbstractEntity) o;
23+
return id == entity.id;
24+
}
25+
26+
@Override
27+
public int hashCode() {
28+
return Objects.hash(id);
29+
}
30+
31+
32+
}

src/main/java/org/launchcode/codingevents/models/Event.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
* Created by Chris Bay
1414
*/
1515
@Entity
16-
public class Event {
17-
18-
@Id
19-
@GeneratedValue
20-
private int id;
21-
16+
public class Event extends AbstractEntity {
2217
@NotBlank(message = "Name is required")
2318
@Size(min = 3, max = 50, message = "Name must be between 3 and 50 characters")
2419
private String name;
@@ -72,26 +67,8 @@ public EventType getType() {
7267
public void setType(EventType type) {
7368
this.type = type;
7469
}
75-
76-
public int getId() {
77-
return id;
78-
}
79-
8070
@Override
8171
public String toString() {
8272
return name;
8373
}
84-
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-
}
92-
93-
@Override
94-
public int hashCode() {
95-
return Objects.hash(id);
96-
}
9774
}

src/main/java/org/launchcode/codingevents/models/EventCategory.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@
1111
* Created by Chris Bay
1212
*/
1313
@Entity
14-
public class EventCategory {
15-
16-
@Id
17-
@GeneratedValue
18-
private int id;
19-
14+
public class EventCategory extends AbstractEntity {
2015
@Size(min=3, message="Name must be at least 3 characters long")
2116
private String name;
2217

@@ -33,27 +28,9 @@ public String getName() {
3328
public void setName(String name) {
3429
this.name = name;
3530
}
36-
37-
public int getId() {
38-
return id;
39-
}
40-
4131
@Override
4232
public String toString() {
4333
return name;
4434
}
45-
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-
}
53-
54-
@Override
55-
public int hashCode() {
56-
return Objects.hash(id);
57-
}
5835
}
5936

src/main/resources/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Database connection settings
22
spring.datasource.url=jdbc:mysql://localhost:3306/coding_events
3-
spring.datasource.username=user
4-
spring.datasource.password=password
3+
spring.datasource.username=coding_events
4+
spring.datasource.password=Co951753
55

66
# Specify the DBMS
77
spring.jpa.database = MYSQL

0 commit comments

Comments
 (0)