简体   繁体   中英

Hibernate @SequenceGenerator return incorrect value in MS SQL

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
@SequenceGenerator(name = "generator", schema = "MD", sequenceName = "sq_base_class")
public Long getId() {
    return id;
}

Hi, I have entity which using MS SQL Sequence for generating ID. but value is incorrect.

com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK_BCL'. Cannot insert duplicate key in object 'MD.BASE_CLASS'. The duplicate key value is (551009).

Example: SequenceGenerator set ID = 551009, but select next value for md.sq_base_class return 551115. How to resolve it? Hibernate-version: 5.3.10.Final

Maybe you lost the allocation size = 1 in @SequenceGenerator

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM