@OneToMany does not work with @JoinFormula

Description

I think @OneToMany annotation does not work at all with @JoinFormula annotation.

I found some old issue https://hibernate.atlassian.net/browse/HHH-9897, but I'm not sure how to interpret it - that is whether it indeed was never supported, or that the specific case in that issue wasn't supported (i.e. with @JoinColumnsOrFormulas).

Having the following entity:

The above mapping does not work. During validation we get exception

Adding reverse side of the relationship (@ManyToOne with @JoinFormula) and adding "mappedBy" to @OneToMany does not change anything - still same error. Also it does not matter that in the attached example we have relation from table A to the same table A - I tested it with different tables with same result.

Test case: https://github.com/hibernate/hibernate-orm/pull/2547
Started here: https://discourse.hibernate.org/t/how-to-use-the-hibernate-joinformula-annotation-with-a-onetomany-jpa-association/1461

Environment

None

Activity

Show:
Nathan Xu
April 22, 2020, 10:14 PM
Edited

From https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#associations-JoinFormula, it seems the annotated field should be some column field in child class. You are using it on parent class and I am almost certain such feature would never be supported, for basically the mechanism aims to provide a customized foreign key, so using it on child class’s ManyToOne field does make sense.

I don’t think Hibernate team will support @OneToMany + @JoinFormula, IMHO. I think the comment in said the same thing.

Gallyam Biktashev
January 15, 2020, 12:09 PM

Any update here?

Alessio Stalla
December 4, 2019, 4:26 PM

I’m interested as well.

Carlos López
November 25, 2019, 10:28 AM

Yes please, or at least an announcement about if it’s going to be ignored forever?

Andrei Ivanov
November 25, 2019, 10:06 AM

Any chance for some attention for this issue?

Assignee

Unassigned

Reporter

Dominik Bieliński

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor