I am using Spring 4 and have the following set up for my data model:
@Entity
@Table(name ="InstanceData")
public class InstanceData {
private Long instanceDataId;
private Long heapUsed; //in bytes
private Long heapMax; //in bytes
@Id
@Column(name="InstanceDataId")
@SequenceGenerator(name="DataSeq", sequenceName="DATA_SEQ")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="DataSeq")
public Long getInstanceDataId() {
return instanceDataId;
}
public void setInstanceDataId(Long id) {
this.instanceDataId = id;
}
@Column(name="HeapUsed")
public Long getHeapUsed() {
return this.heapUsed;
}
public void setHeapUsed(Long heapUsed) {
this.heapUsed = heapUsed;
}
@Column(name="HeapMax")
public Long getHeapMax() {
return this.heapMax;
}
public void setHeapMax(Long heapMax) {
this.heapMax = heapMax;
}
I let Hibernate create the schema automatically. I then try the following SQL (on the H2 db):
insert into instance_data (heap_used, heap_max) values (100, 100);
The error I get is: Error: NULL not allowed for column "INSTANCE_DATA_ID"; SQLState: 23502
My question is why doesn't it auto generate the primary key? How should I change my data model configuration so that the primary key is auto generated (starting at 1)? Thanks for your help.
I would like to understand why even though I am using the @GeneratedValue annotation, the primary key is not auto generated.