In spring boot JPA I tried to implement sequence generator but it is not working. the following is my entity
@Entity
@Table(name = "role_level")
public class RoleLevel implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "role_level_sequence", sequenceName = "role_level_id_seq",allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "role_level_sequence")
@Column(name = "id", updatable = false)
private Long id;
@Column(name = "role_level")
private String roleLevel;
@Column(name = "role_level_description")
private String roleLevelDescription;
//getters and setters
}
when I insert value in directly through the database then next sequence from the db is not getting in jpa.it shows
org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "role_level_pkey"
Detail: Key (id)=(7) already exists.
But the console shows
Hibernate: select nextval ('role_level_id_seq')
I think its not working. Is there any solution for this.?