If an Entity contains an ElementCollection map, and entries are added to the map with null values, those entries are not persisted.
However, if that same table is audited with Envers, Hibernate does attempt to insert an audit row for the non persisted map entries. This results in an exception because the value field in the audit table has a not null constraint.
The correct behavior would be for Hibernate to insert the map entries with null values. The Envers constraint seems reasonable, so if auditing is needed for the ElementCollection, a not null constraint could be declared for the ElementCollection using @column(nullable=false). Hibernate should still attempt to insert the row thus allowing the application to catch a PersistenceException triggered by an EntityManager.flush().
|