I have a table with an autoincrement column, as described here
This is how it's defined in Java/Hibernate:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int ID;
And this is how the column is defined in the CREATE TABLE (note, no sequence):
"ID" INTEGER CS_INT GENERATED BY DEFAULT AS IDENTITY
Now, I want to insert a row in the table and retrieve the resulting id. The problem is that the driver doesn't support Statement.RETURN_GENERATED_KEYS
to retrieve the id with a fetch statement.
On the other hand, since I don't have a sequence created I cannot use nextval
. Any ideas how to get the autoincremented id?
Note: JDBC has similar problem, it's not Hibernate specific.
UPDATE
Sample code (in Java/Hibernate):
val c = new MyJpaClass
c.code = 1
c.name = "abc"
c.version = 0
entityManger.getTransaction.begin
entityManger.persist(c)
entityManger.getTransaction.commit
// c.id should be populated here with the assigned autoincremented id