@@ -25,7 +25,8 @@ public List<Sighting> getAllSighting() {
25
25
}
26
26
27
27
public Sighting getSighting (String id ) throws Exception {
28
- Sighting entity = entityManager .find (Sighting .class , id );
28
+ UUID uuid = UUID .fromString (id );
29
+ Sighting entity = entityManager .find (Sighting .class , uuid );
29
30
if (entity == null ) {
30
31
throw new Exception ("Sighting with id of " + id + "doesn't not exist." );
31
32
}
@@ -34,17 +35,24 @@ public Sighting getSighting(String id) throws Exception {
34
35
35
36
@ Transactional
36
37
public Sighting createSighting (String id ){
38
+ UUID uuid = UUID .fromString (id );
37
39
Sighting entity = new Sighting ();
38
- entity .setId (id );
40
+ entity .setId (uuid );
39
41
entity .setCapturedDate (new Date ());
40
42
entityManager .persist (entity );
41
43
return entity ;
42
44
}
43
45
44
46
@ Transactional
45
47
public Sighting addBird (String sightingId ,String birdId ) throws Exception {
46
- Sighting sightingEntity = entityManager .find (Sighting .class , sightingId );
47
- Bird birdEntity = entityManager .find (Bird .class , birdId );
48
+ System .out .println ("Sight" );
49
+ System .out .println (sightingId );
50
+ System .out .println ("Bird" );
51
+ System .out .println (birdId );
52
+ UUID suuid = UUID .fromString (sightingId );
53
+ UUID buuid = UUID .fromString (birdId );
54
+ Sighting sightingEntity = entityManager .find (Sighting .class , suuid );
55
+ Bird birdEntity = entityManager .find (Bird .class , buuid );
48
56
if (sightingEntity == null ) {
49
57
throw new Exception ("Sighting with id of " + sightingId + "doesn't not exist." );
50
58
}
@@ -61,8 +69,10 @@ public Sighting addBird(String sightingId,String birdId) throws Exception {
61
69
62
70
@ Transactional
63
71
public Sighting removeBird (String sightingId ,String birdId ) throws Exception {
64
- Sighting sightingEntity = entityManager .find (Sighting .class , sightingId );
65
- Bird birdEntity = entityManager .find (Bird .class , birdId );
72
+ UUID suuid = UUID .fromString (sightingId );
73
+ UUID buuid = UUID .fromString (birdId );
74
+ Sighting sightingEntity = entityManager .find (Sighting .class , suuid );
75
+ Bird birdEntity = entityManager .find (Bird .class , buuid );
66
76
if (sightingEntity == null ) {
67
77
throw new Exception ("Sighting with id of " + sightingId + "doesn't not exist." );
68
78
}
@@ -83,15 +93,17 @@ public List<Bird> getAllBirds() {
83
93
}
84
94
85
95
public Bird getBird (String id ) throws Exception {
86
- Bird entity = entityManager .find (Bird .class , id );
96
+ UUID uuid = UUID .fromString (id );
97
+ Bird entity = entityManager .find (Bird .class , uuid );
87
98
if (entity == null ) {
88
99
throw new Exception ("Bird with id of " + id + "doesn't not exist." );
89
100
}
90
101
return entity ;
91
102
}
92
103
93
104
public List <Sighting > getSightingsByBird (String id ) throws Exception {
94
- Bird entity = entityManager .find (Bird .class , id );
105
+ UUID uuid = UUID .fromString (id );
106
+ Bird entity = entityManager .find (Bird .class , uuid );
95
107
if (entity == null ) {
96
108
throw new Exception ("Bird with id of " + id + "doesn't not exist." );
97
109
}
@@ -115,11 +127,16 @@ public Bird createBird(String genusName, String name) throws Exception {
115
127
116
128
@ Transactional
117
129
public Bird deleteBird (String id ) throws Exception {
118
- Bird entity = entityManager .find (Bird .class , id );
130
+ UUID uuid = UUID .fromString (id );
131
+ Bird entity = entityManager .find (Bird .class , uuid );
119
132
if (entity == null ) {
120
133
throw new Exception ("Bird with id of " + id + "doesn't not exist." );
121
134
}
122
135
136
+ for (Sighting sighting : entity .getSightings ()) {
137
+ sighting .removeBird (entity );
138
+ }
139
+
123
140
entityManager .remove (entity );
124
141
return entity ;
125
142
}
0 commit comments