Sleeping double duplicate primary key on restart using GenerationType.TABLE

We encounter a problem when we have subclasses of events that use GenerationType.TABLE to generate the primary key, and when we restart the servers, we get repeated primary key errors.

We use SQL Server and Hibernate version 3.5.1-Final.

Here's what the Hibernate annotations look like:

@Entity @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Event { @Id @GeneratedValue(strategy = GenerationType.TABLE) private long eventID; 

we do not specify allocize, so we use the default value. The hibernation sequence table is growing, but it seems that when it is restarted, it reuses the identifiers already in use.

+6
java sql sql-server orm hibernate
source share
1 answer

Try GenerationType.AUTO or SEQUENCE. AUTO can work using hibernation magic, but SEQUENCE should create, oddly enough, a sequence in the database that will be used to obtain unique identifiers. Which SQL Server are you using?

0
source share

All Articles