Hibernate Generated Value strategy

hibernate, hql, java, sql

Solution

Database do not care if there is holes in the sequence. Also in general it is possible and most likely easier to change application design so that it does not expect list of id values to not contain holes.

If some odd reason forces such a design, you have to use custom generator. Implementation details can be found via this question: Hibernate ID Generator

Problem

I am using this code in hibernate. ``` @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name="RightID", unique=true, nullable=false) ``` The problem is when i delete a row the 'RightId' don't remain in sequence. I want something like, hibernates should check id, if some id value is missing it must give that value to 'RightsId' otherwise proceed normally

Original source

Related problems