-
Bug
-
Resolution: Done
-
Major
-
7.2.0.GA, 7.2.1.GA, 7.2.2.GA
Part of the fix for HHH-12282 made nullability of join tables dependent on JpaCompliance.isJpaCacheComplianceEnabled().
An example is in the SingleTableEntityPersister constructor:
isNullableTable[j] = join.isOptional() || creationContext.getSessionFactory() .getSessionFactoryOptions() .getJpaCompliance() .isJpaCacheComplianceEnabled();
In the discussion for HHH-12282, there was mention that we were not able to come up with an example where table nullability would caused a problem when caching multi-table entities. The related changes should have gotten reverted as part of HHH-12282, but did not.
By default, when EntityManager is used, JpaCompliance().isJpaCacheComplianceEnabled() returns true.
A side-effect is that Hibernate will not insert a row with all null values into a secondary table when that table is mapped with org.hibernate.annotations.Table(appliesTo="...", optional=false)
The original description indicates that in 5.1, when an entity join table is mapped with org.hibernate.annotations.Table(appliesTo="...", optional=false), and there is no row in the join table for that entity, that the entity was ignored; in 5.3, it is no longer ignored.
The reason it was ignored in 5.1 is that, for single-table inheritance, Hibernate uses an INNER JOIN to join the root entity's main table with the secondary table.
In 5.3, since, by default with EntityManager, JpaCompliance().isJpaCacheComplianceEnabled() returns true, Hibernate assumes that the secondary table will be nullable, even when mapped with org.hibernate.annotations.Table(appliesTo="...", optional=false), so Hibernate uses an OUTER JOIN to join the root entity's main table with the secondary table. Because of the OUTER JOIN, Hibernate no longer ignores the entity with no row in the secondary table. The fix for this issue will restore the INNER JOIN when joining a secondary table for an entity with single-table inheritance. Secondary tables for entities with joined inheritance will continue to be joined using an OUTER JOIN, as was done in 5.1.
Although Hibernate does not support having data in the database that is inconsistent with entity mappings, the bug described in the original description will be fixed.
----------------------------------------------------------------------------------------------------------------------------
Original description:
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 (database layer and in bean validation) in various scenarios for properties persisted in the secondary table.
It was discovered that the secondary table was corrupt and rows were missing for one or more entities. Hibernate did not load the invalid entity rows in older Hibernate releases.
- is incorporated by
-
JBEAP-16779 [GSS](7.2.z) Upgrade Hibernate ORM from 5.3.10 to 5.3.11
- Closed
- links to