• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hibernate Error inserting data into a column with DEFAULT and NOT NULL constraints

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your field cannot have default constraints defined; if it did, Hibernate could insert into it no bother.
 
Let nothing stop you! Not even this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic