Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Any idea why might my review have an id of 2 instead of 1?
I've followed all of the steps so far faithfully and my rest endpoint is functioning as it should be, except for the fact that my first review has an id of 2 instead of 1.
I think something is happening where the id of the course and review are conflicting. I tried adding a few more courses and reviews and that seems to be the case. The courses and reviews are behaving as if they are all in the same array (first course has id of 1, first review has id of 2, second review has id of 3, second course has id of 4, etc.).
So my best guess is there is something going wrong with the repositories and/or how they are loaded, but I'm not 100% sure. Has anyone else had this problem? Does anyone have any suggestions?
I fixed my problem by changing the strategy value in the @GeneratedValue annotation from GenerationType.AUTO to GenerationType.IDENTITY in the BaseEntity parent class.
Here is the documentation for the GenerationType enum that helped me: https://docs.oracle.com/javaee/5/api/javax/persistence/GenerationType.html