Entity graph attribute node is ignored if the entity is mapped by the Primary Key column

Description

We have an User entity. To collect some statistics we have a database view, counting comments, for instance. This view is mapped by a UserStatistic entity.
The User entity references the UserStatistics. As the UserStatistic represents a database view it has the same id as the User entity and is referenced by the id column.

Doing a query with a loadgraph loading the statistics for the user, everything is fine.
The sql is as aspected.

If the user is get by id the statistic is missing. The sql.

I did some debugging and found the following reason:

In AbstractLoadPlanBuildingAssociationVisitationStrategy an AssociationKey with table name and column name is generated to prevent circular references.
As the user statistics uses the same column it is ignored in MetamodelGraphWalker.

I am willing to deliver a patch for this bug, but I am not sure what would be the best way to solve it.
To prevent circular refer it should either take the referenced table into account or the attribute in the entity?

Why is this not happening if I get the entity by a query?
PR with testcase will follow.

Seems to be very simular to:

Attachments

1

Activity

Show:

Oliver Breidenbach June 14, 2016 at 11:02 AM

I think the cycle detection should be enhanced. Maybe Steve can give us a hint how to fix this.

Vladimir Martinek June 14, 2016 at 10:32 AM

Thank you, did not notice the pull. I have executed the test.

is very similar, except the (not really a)cycle is detected directly by MetamodelGraphWalker.visitedAssociationKeys, while the in it is detected by AbstractLoadPlanBuildingAssociationVisitationStrategy. I have tried to remove the cycle detection from MetamodelGraphWalker.visitedAssociationKeys and then the cycle was detected by AbstractLoadPlanBuildingAssociationVisitationStrategy, so we are looking at the same issue.

I have noticed that marking the relations EAGER instead of LAZY loads the joins fine while using the same MetamodelGraphWalker and AbstractLoadPlanBuildingAssociationVisitationStrategy. It does it as a subsequent SELECT. Of course we can't make the relations EAGER.

I believe fixing will fix too. The question is how - better cycle detection? Or subsequent SELECT just like the EAGER does? I was hoping to get the answer on the forum, but no luck.

Oliver Breidenbach June 13, 2016 at 11:21 AM

Hello Vladimir,

Why are you not using the test from my pull request? It shows the failure.
You can run the test with:

My test uses an EntityGraph, yours not, maybe that causes the different behavior?
Oliver

Vladimir Martinek June 13, 2016 at 10:58 AM

Hello,

I have tried to build and execute example based on your instructions in HHH-10745. Attaches as hhh_10842_v1.tar.gz
Unfortunately I can not reproduce the problem you report. Could you please modify my example so that I can reproduce it?
From your comment I judge we both suffer from the same problem, but I can't confirm without testing it first.

Vladimir

Details

Assignee

Reporter

Components

Affects versions

Priority

Created June 13, 2016 at 9:28 AM
Updated November 7, 2018 at 5:24 AM