Encountering not-null constraint violations related to a secondary table for an entity in Hibernate

Solution Verified - Updated -

Issue

  • An entity is defined with a non-optional secondary table
  • After migrating from an older EAP / Hibernate release to EAP 7.2 (Hibernate 5.3), encountering not-null constraint violations in various scenarios for properties persisted in the secondary table

    ... java.sql.BatchUpdateException: ORA-01400: cannot insert NULL into ("MYSCHEMA"."MY_JOIN_TABLE"."APROPERTY")
    
            at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:11190)
            at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:244)
            at org.jboss.jca.adapters.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:1180)
            at org.hibernate.engine.jdbc.batch.internal.BatchingBatch.performExecution(BatchingBatch.java:118)
           ...
    
    ... javax.validation.ConstraintViolationException: Validation failed for classes [org.mypackage.MyEntity] during update time for groups [javax.validation.groups.Default, ]
    List of constraint violations:[
            ConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=aproperty, rootBeanClass=class org.mypackage.MyEntity, messageTemplate='{javax.validation.constraints.NotNull.message}'}
    ]
            at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.validate(BeanValidationEventListener.java:140)
            at org.hibernate.cfg.beanvalidation.BeanValidationEventListener.onPreUpdate(BeanValidationEventListener.java:88)
            at org.hibernate.action.internal.EntityUpdateAction.preUpdate(EntityUpdateAction.java:248)
            ...
            at org.hibernate.query.Query.getResultList(Query.java:135)
            ...
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 7.2
  • Hibernate 5.3

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content