java - Records in DB are not one by one. Hibernate -
I have two column IDs: ID (AI) and NAME (UNIQUE). When I'm adding a new record for DB, then OK, this record has the ID = 1.
When I'm trying to add a record with the existing name, I'm getting the error: com.mysql.jdbc.exceptions.jdbc4.MySQLInitgrityConstraintViolationException: Duplicate entry I want to add the next record, with valid data and this record has id = 3. Is there any remedy for this? I have an ID like this: 1 | 2 | 3 not 1 | 3 | 5 etc. Or should I first check that this name exists? Which option is better? My code: There are different ID generation strategies if the ID is generated based on the sequence When the "final price" is requested, its final number immediately increases. There will be no problem you have told, if the ID is generated based on the table.
Public boolean save () {hibernate.beginTransaction (); hibernate.save (userObject); Committed to hibernate.getTransaction (). hibernate.close (); Back true; }
Comments
Post a Comment