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 trial

Java Hibernate Basics Persisting Data with Hibernate Fetching Data with Hibernate

Jani Eronen
Jani Eronen
5,767 Points

Not 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

Could you post your code here for us? That will make it easier to see what/where the error might be.

4 Answers

Kourosh Raeen
Kourosh Raeen
23,733 Points

Closing 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
Olga Ivancic
8,137 Points

Thank you, I had the same problem and closing the session factory solved the problem.

Try 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
Jani Eronen
5,767 Points

Here: 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
Doli Harahap
6,246 Points

It 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?