Allow "mappedBy" to reference attribute defined on superclass of "targetEntity"

Description

When an entity (such as Customer) has a @OneToMany relationship with a specific entity subclass of an entity where the owning relationship field is defined, Hibernate does not find the appropriate property on the superclass.

This or a similar bug was reported before but was closed as WONTFIX without explanation. We encountered this bug after refactoring our code to support differing metadata on different order types, and this seems like a clear case of the sort of field that should be placed on the supertype (though unfortunately the 2.0 spec doesn't address the issue at all).

see <ANN-390>

Environment

4.2.0 snapshot for 2012-09-19

Activity

Show:
Christopher Smith
September 27, 2012, 1:03 AM

Unless and until this feature is implemented, I suggest making the error message for this particular case more specific.

AdamW
December 3, 2013, 6:12 PM

I disagree that this is situation is always a result of bad data model design. Please see my attachment.

Piotr Findeisen
December 12, 2013, 9:17 AM

Hi

This seems to be a popular topic. Already ANN-390, ANN-558, HHH-4233, ANN-615....

What struck me today is the inconsistency between @OneToOne(mappedBy) and @OneToMany(mappedBy). With Order and SpecialOrder as in the example above (I'm using SINGLE_TABLE @Inheritance for Order):

works OK

DOESN'T WORK

Why can I reference parent class property in @OneToOne-mappedBy and have the discriminator added to SQL but I cannot do the same on @OneToMany-mappedBy?

PavelV
February 10, 2016, 10:52 AM

Any news?

Paul Nest
October 27, 2016, 1:32 PM

I'm curious about workaround. If we change AccessType to PROPERTY and override getter in the child class will it work?

Assignee

Unassigned

Reporter

Christopher Smith

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major