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! While you're at it, check out some resources Treehouse students have shared here.
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 trialJani Eronen
5,767 PointsNot sure what I did wrong, but the the id of my contacts does not generate the way it should. It goes like: 1, 33,65,97
Generated value in Contact.java is set like it is in the example
4 Answers
Kourosh Raeen
23,733 PointsClosing the sessionFactory
at the bottom of the main()
method will fix it as explained by one of the answers here:
http://stackoverflow.com/questions/29936707/hibernate-wrong-generate-auto-id-increment
Olga Ivancic
8,137 PointsThank you, I had the same problem and closing the session factory solved the problem.
Peter Kinsella
9,154 PointsTry this: @GeneratedValue(strategy = GenerationType.TABLE). It's odd but maybe, for some strange reason the video has some minor differences to how our DBs are configured, as I have the exact same code and I encountered the exact same problem ( ID's of 1 , 32, etc).
Jani Eronen
5,767 PointsHere: https://github.com/JEronen/hibernateCourse. I "solved" the problem with the code introduced in here: https://teamtreehouse.com/community/contact-id-does-not-increment-by-1 but that does not help me to understand why my remake of course's project won't work without it
Doli Harahap
6,246 PointsIt really depends on the strategy I guess. https://javaee.github.io/javaee-spec/javadocs/
Different strategy will result in different sequential number. For me "TABLE" will increment by 1. Wondering why I follow exactly what Chris did by using "IDENTITY" but incrementing by 32?
Shane Robinson
7,324 PointsShane Robinson
7,324 PointsCould you post your code here for us? That will make it easier to see what/where the error might be.