H Paul wrote:[code=java]@Column(name = "NUMBER", columnDefinition="INTEGER GENERATED BY DEFAULT AS IDENTITY")
private int number;
IDENTITY_GENERATION=BY DEFAULT
2 things:
1) You have the number member variable as a primitive int. So by default its value is set to 0
2) Your schema says that the column is identity generation
by default which means that if the variable mapped to the column already has a value then the DB will just use it and will not generate a new value for. In this case, the variable does have a value of 0 so the DB just skips the generation.
You have 2 ways to solve this:
1) Change the variable type from int to Integer and let the value be null for that variable when you are persisting
2) Change the identity generation int the schema from
by default to
always (see this for details
http://docs.oracle.com/javadb/10.8.2.2/ref/rrefsqlj37836.html). That way, the DB will always generate a value even if the insert query which gets generated by JPA already provides a value for that column. Of course, you'll have to consider your application semantics to decide whether you want to switch the generation type to "always".
Edited: Minor edit - its instead of it's