Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

quaff
Copy link
Contributor

@quaff quaff commented Dec 15, 2023

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]

https://hibernate.atlassian.net/browse/HHH-16144

…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]
@quaff quaff changed the title HHH-16144 Add test for issue HHH-16144 AbstractManagedType should look up declared concrete generic attributes before super attributes Dec 15, 2023
@quaff
Copy link
Contributor Author

quaff commented Dec 15, 2023

Could you take a look? @mbladel

@quaff quaff marked this pull request as draft December 15, 2023 08:48
@hibernate-github-bot
Copy link

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 HHH-\d+
    ↳ Offending commits: [15e887d]

› This message was automatically generated.

@quaff quaff marked this pull request as ready for review December 15, 2023 09:28
Copy link
Contributor

@mbladel mbladel left a 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() );
});
Copy link
Member

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.

@mbladel
Copy link
Contributor

mbladel commented Dec 15, 2023

Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants