问题
EMPLOYEE.java
@Entity
@Table(name="EMPLOYEE")
public class Employee implements Serializable {
@Id
@GeneratedValue( strategy = GenerationType.TABLE)
EMPLOYEE (TABLE)
1 3/13/2013 911 Jack Bauer
32768 3/13/2013 911 Jack Bauer
65536 3/13/2013 911 Jack Bauer
98304 3/13/2013 911 Jack Bauer
HIBERNATE_SEQUENCES(TABLE) HOLDING CORRECT NUMBER
EMPLOYEE 4
回答1:
@TableGenerator(name="tabgen",table="employee-id",pkColumnName="name",valueColumnName="value",allocationSize=1)
@GeneratedValue(strategy=GenerationType.TABLE, generator="tabgen")
however, its always better to use increment or sequence instead of table generation if you need the ids to be in sequence. the random ids which u see with default table strategy is because of the need to support multiple threads all simulteneously trying to insert.
来源:https://stackoverflow.com/questions/15393534/hibernate-provides-next-generated-id-32768-and-so-on-65536-98304