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:

  Public boolean save () {hibernate.beginTransaction (); hibernate.save (userObject); Committed to hibernate.getTransaction (). hibernate.close (); Back true; }   

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.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -