hibernate-test-case-templates icon indicating copy to clipboard operation
hibernate-test-case-templates copied to clipboard

HHH-18469 Bug reproduction - java.lang.AssertionError

Open RadekHS opened this issue 6 months ago • 2 comments

Jira card: HHH-18469

Description

When migrating to fresh hibernate, some of our queries stopped working, resulting in the following stack trace:

java.lang.AssertionError
	at org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping.createTableGroupJoin(ToOneAttributeMapping.java:1985)
	at org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping.createTableGroupForDelayedFetch(ToOneAttributeMapping.java:1806)
	at org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping.createCircularBiDirectionalFetch(ToOneAttributeMapping.java:1345)
	at org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping.resolveCircularFetch(ToOneAttributeMapping.java:1024)
[...]

The issue is not resolved by HHH-18086, which I tested by a fresh SNAPSHOT version of the library.

Bug description

I found out the issue in the Hibernate's fetch builder logic.

  • In case of having the following entities: A, B1, B2, C, where B1, and B2 refer to the same table.
  • Also, having a mapping A.b, and C.b, and the following SQL:
Select a from A a
LEFT JOIN FETCH a.b b
LEFT JOIN FETCH b.c c
  • The issue occurs. This can be fixed by renaming the mapping, for example from: A.b to A.b1

Work a round

Changing entity's A field b name to any name that differs from entity's C field b. It works both ways - changing entity's C field b name also works.

RadekHS avatar Aug 08 '24 15:08 RadekHS