-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HHH-16144 AbstractManagedType should look up declared concrete generic attributes before super attributes #7630
Conversation
…c attributes before super attributes Fix java.lang.IllegalArgumentException: Unable to locate Attribute with the given name [xxx] on this ManagedType [java.lang.Object] at org.hibernate.metamodel.model.domain.AbstractManagedType.checkNotNull(AbstractManagedType.java:225) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final] at org.hibernate.metamodel.model.domain.AbstractManagedType.getAttribute(AbstractManagedType.java:148) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final] at org.hibernate.metamodel.model.domain.AbstractManagedType.getAttribute(AbstractManagedType.java:43) ~[hibernate-core-6.3.1.Final.jar:6.3.1.Final] at org.springframework.data.jpa.repository.query.QueryUtils.requiresOuterJoin(QueryUtils.java:836) ~[spring-data-jpa-3.2.0.jar:3.2.0]
Could you take a look? @mbladel |
Thanks for your pull request! This pull request does not follow the contribution rules. Could you have a look? ❌ All commit messages should start with a JIRA issue key matching pattern › This message was automatically generated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not correct, and the failing tests you changed confirm that. The reported java type for generic paths should be the generic one. Using generic paths in Hibernate queries works correctly, so the issue described in the Jira is due to problematic code on Spring's side, as we had already said.
scope.inTransaction( entityManager -> { | ||
EntityType<Book> bookType = entityManager.getMetamodel().entity( Book.class ); | ||
assertEquals( Owner.class, bookType.getAttribute("owner").getJavaType() ); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this assertion is correct. As with Java's reflection API, EntityType.getAttribute()
gives you a representation of the inherited attribute as it was declared in the supertype. It does not do substitution of generic type arguments from the inheriting subclass, and I don't see any support anywhere in the JPA API or specification which hints that it should.
So I believe that it's correct for Hibernate to return Object.class
here, and I think this PR should be closed.
Closing this. |
Fix
https://hibernate.atlassian.net/browse/HHH-16144