
Hi,
I'm trying to implement a id generator in Hibernate, but I'm having a problem. Hibernate doesn't seems to reset the counting when the id is generated. For example:
1 - In PostgreSQL I have a table (that entries were done with Hibernate script):
carId|car_description
1|john
2|mike
3|Peter
2 - Now, I clean the table, and next time I insert a new value on car_description, when I think that hibernate catch the min value(0 because the db is empty), it inserts the last value created (saved in memory perhaps).
carId|car_description
4|Michael
My class is:
@Entity @Table(name="tb_career") public class Career implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_career") @SequenceGenerator(initialValue = 1, allocationSize = 1, name = "seqcareer", sequenceName = "seqcareer")
@Column(name="car_id", unique=true, nullable=false) private Integer carId; @Column(name="car_description", length=255) private String carDescription; //bi-directional many-to-many association to Course @ManyToMany(mappedBy="tbCareers") private List<Course> tbCourses;
Kind Regards! Thanks!