[hibernate-dev] hibernate.jpa.compliance.caching and nullable secondary tables

Gail Badner gbadner at redhat.com
Fri May 24 21:07:26 EDT 2019


The Javadoc for JpaCompliance#isJpaCacheComplianceEnabled says:

* @implNote Effects include marking all secondary tables as non-optional.
The reason

* being that optional secondary tables can lead to entity cache being
invalidated rather
* than updated.

But, the way it's used is the opposite (marks all secondary tables as
optional): [1]
isNullableTable[j] = join.isOptional()
                         || creationContext.getSessionFactory()

 .getSessionFactoryOptions()
                                                   .getJpaCompliance()

 .isJpaCacheComplianceEnabled();

Even if a secondary table is explicitly mapped as non-optional using
@org.hibernate.annotations.Table(appliesTo=...,optional=false),
when hibernate.jpa.compliance.caching=true, Hibernate assumes that
secondary tables are nullable. This causes an outer join to be used in
queries, when an inner join could be used instead.

The property was added by HHH-12282 [2], which also mentions that the
intention is to mark all tables as non-optional. HHH-12282 also has a
comment [3] that says:

"I think its safe enough here to simply say that compliance means we omit
the table-span check at all."

Should the determination of whether a table is nullable depends only
on org.hibernate.mapping.Join#isOptional, like the following?

isNullableTable[j] = join.isOptional();

JpaCompliance().isJpaCacheComplianceEnabled() == true would still skip
invalidation.

WDYT?

Regards,
Gail

[1]
https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/persister/entity/SingleTableEntityPersister.java#L181-L185
[2] https://hibernate.atlassian.net/browse/HHH-12282
[3]
https://hibernate.atlassian.net/browse/HHH-12282?focusedCommentId=101168&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-101168


More information about the hibernate-dev mailing list