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 trialSamuel Zhen
33,571 PointsGenerationType.IDENTITY problem on Hibernate for primary field
I'm facing a problem on auto generate id number for primary field using Hibernate. It does not generate as it should be, it jumps to 32 or 33.
After browsing through community, i found someone who face the same problem and there's a suggestion to use @GeneratedValue(strategy = GenerationType.TABLE).
But this forum said, TABLE is not recommended. I'm not really understand why though.
Any idea how to solve this?
Craig Dennis , Chris Ramacciotti
Thanks
1 Answer
Alexander Nikiforov
Java Web Development Techdegree Graduate 22,175 PointsCheck my answer on StackOverflow
TL;DR
When you DON"T close SessionFactory properly and exiting application, then your database is eating out your IDs
add
sessionFactory.close()
at the end of the Main
class