I have a column in our Oracle database that is defined with NOT NULL and DEFAULT constraints. When I try to insert a row into this table using JPA, I get the following error.
Caused by: java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("TT_OWNER"."TIMETRACKER_SHIFT_ELEMENT"."SHIFT_STATUS")
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:342)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10720)
at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
I think Hibernate is trying to do the insert in 2 steps. In the first step it tries to insert without the DEFAULT value and in the second step, it updates the same record with the DEFAULT value. I was able to fix this by explicitly setting the column value with the DEFAULT value in my
java code. I believe I shouldn't have to do it. Hibernate seems to be finding the NOT NULL constraint fine. But it should also find the DEFAULT constraint and apply it during insertion instead of throwing an error. Is this a Hiberante bug?