Oracle 12c Identity column with Hibernate 5 Oracle 12c Identity column with Hibernate 5 spring spring

Oracle 12c Identity column with Hibernate 5


It seems that Hibernate 5.0.X does a query trying to get the ID value from the database when you specify GenerationType.IDENTITY. This value is retrieved from a java ResultSet using an appropriate getXXX depending on the type you used to declare your ID. Either resultSet.getString(columnIndex) or resultSet.getRowId(columnIndex) work in my case but RowId cannot be used in a JPA bean.

If you try changing it ID to string it should work, even though it looks like a bug to me:

@Id@Column(name="PRD_ID")@GeneratedValue(strategy=GenerationType.IDENTITY)private String prdId; 


you can do it as below:

CREATE TABLE identity_test_tab ( id NUMBER GENERATED BY DEFAULT AS IDENTITY, description VARCHAR2(30));

SQL> INSERT INTO identity_test_tab (description) VALUES ('Just DESCRIPTION');

1 row created.

SQL> INSERT INTO identity_test_tab (id, description) VALUES (999, 'ID=999 and DESCRIPTION');

1 row created.

SQL> INSERT INTO identity_test_tab (id, description) VALUES (NULL, 'ID=NULL and DESCRIPTION');INSERT INTO identity_test_tab (id, description) VALUES (NULL, 'ID=NULL and DESCRIPTION') *ERROR at line 1:ORA-01400: cannot insert NULL into ("TEST"."IDENTITY_TEST_TAB"."ID")

since always identity column should have value not null