@Where annotation not working with entities that use inheritance

Description

Usage of the @Where annotation on a collection that contains entities that make use of JOINED inheritance strategy results in incorrect SQL.

Hibernate is assuming that the column specified in the @Where annotation will always be on the table that belongs to the entity in the collection, instead of also checking the super-class tables.

For example, consider the following data model and mapping code:

AbstractProjectVersion.java

ApplicationProjectVersion.java

Application.java

Loading Application will issue incorrect SQL, where PROJ_VSN_EFF_TO_DTM is being referenced on the DFIP_APPLN_PROJ_VERSION table, rather than its super-class (DFIP_PROJECT_VERSION).

A unit test demonstrating the issue is attached.

Environment

None

Activity

Show:
Burak Bayrakdar
December 5, 2017, 9:36 AM
Edited

I have the exact problem with my Hibernate version 5.1.12.Final with JPA
My superclass has @MappedSuperClass, and @Where annotation is not inherited from it, I need to duplicate same silly annotation for hundreds of entities that are all extending same base entity.

Val Blant
December 7, 2017, 4:18 AM
KS
November 26, 2018, 10:42 AM

@Inheritance is hard to use in serious cases - envers doesn't work (HHH-9770), @where doesn't work (useful also for soft delete).

Assignee

Unassigned

Reporter

Val Blant

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure