UnknownTableReferenceException on @ElementCollection of @Embeddable containing a @MayToOne with a @ManyToMany

Description

When “Hibernate.initialize(plan.getTransfers().get(0).getSubPlan().getEvents())” I get a “UnknownTableReferenceException: Unable to determine TableReference (`SubPlan`) for `Plan.transfers.events`”.

Hibernate seems to overlook the intermediate entity “SubPlan“ in the embeddable “Transfer“ here. The path above should be `Plan.transfers.subPlan.events`.

Reduced code:

@Entity public class Plan { @Id public Integer id; @ElementCollection @CollectionTable(name = "transfer", joinColumns = @JoinColumn(name = "plan_id")) public List<Transfer> transfers; public List<Transfer> getTransfers() { return transfers; } } @Embeddable public class Transfer { @ManyToOne @JoinColumn(name = "subplan_id") @Cascade(ALL) public SubPlan subPlan; public SubPlan getSubPlan() { return subPlan; } } @Entity public class SubPlan { @Id public Integer id; @ManyToMany @Fetch(SUBSELECT) @Cascade(ALL) public List<Event> events = new ArrayList<>(); public List<Event> getEvents() { return events; } } @Entity public class Event { @Id public Integer id; public String name; }

Activity

Show:

Andrea Boriero November 23, 2022 at 12:31 PM

Thanks for the test!

Markus Heiden November 14, 2022 at 10:52 AM

I added the (failing) test case as pull request (https://github.com/hibernate/hibernate-orm/pull/5557) to the details. I hope that was the right place to add it.

Antoine Rey November 14, 2022 at 7:44 AM

This code was working from Hibernate ORM 3.6.9.Final (maybe prior?) to 5.6.3.Final.

Fixed

Details

Assignee

Reporter

Worked in

Fix versions

Affects versions

Priority

Created November 13, 2022 at 11:19 AM
Updated December 7, 2022 at 2:24 PM
Resolved December 5, 2022 at 1:14 PM