-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Unable to locate Attribute with the given name on parametrized supertype #3307
Comments
It should be fixed by #3275 |
Hibernate 6 changed how the Meta-model behaves. Creating a join on You can reproduce the issue via: CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Object> query = cb.createQuery();
Root<ChildA> from = query.from(ChildA.class);
Join<Object, Object> join = from.join("parent");
Bindable<?> model = join.getModel();
if(model instanceof SingularAttribute
&& ((SingularAttribute<?, ?>) model).getType() instanceof ManagedType mt){
Class<?> type = mt.getJavaType(); // returns Parent instead of ParentA
mt.getAttribute("id");
} As we're receiving invalid types in the first place, I don't see how we can fix the issue without compensating for a Hibernate issue. |
Hi there, i've created a hibernate ticket (HHH-17651) and they say, that the problem is not on their side either - which i can understand, because if i'm doing such things:
it seems to work fine and the exception is coming from the QueryUtils class, which cannot locate the attribute. But i'm just the man in the middle here, that's trying to get his application working again.... |
It's a pity that our code has worked for ages. Now that Hibernate has decided to revise their implementation, existing applications and libraries fall apart because they suddenly require Once we have some time, we try to work around Hibernate's changes and fix yet another Hibernate inconvenience on our side. |
Thank you very much for responding ! To be more specific: And for this case, i dont have a clue how i could do a workaround Have a good day! |
Hi there, My problem is coming from QueryUtils.requiresOuterJoin. In the context above (stackwise), all joins/treats are working well, which means, the context is aware of a treat for the parent class and will use the correct type (and i have no problem doing a treat join, which i acutally had to do in past versions). So what actually seems to be the problem is, that "requiresOuterJoin" tries to locate the "id" attribute in the next path recursion (child.parent.id) and fails with an exception in
because getAttribute will ignore the treat and do a null check afterwards. I suppressed this exception using the debugger, and then, the code would - in my case - work correctly! So maybe it would be enough e.g. using findAttribute without the null-check, instead of getAttribute, since the code following this line, is expecting null values. I'm aware, that the problem might be a bit more complex, since i'm only working with leafProperties that dont need a further join, so there is no "requiresOuterJoin" decision needed. But maybe this helps implementing some kind of fix... For me, i don't think i can workaround this problem somehow - or do you have any idea? Thanks! |
ManagedType may be erased type if the attribute is declared as generic, take Hibernate 6.x for example, exception is thrown like: ``` java.lang.IllegalArgumentException: Unable to locate Attribute with the given name [name] 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] ``` Fix spring-projectsGH-3274 Fix spring-projectsGH-3307
Resolved via #3375 |
Hi there,
during the update to spring boot 3.x i encountered some issues related to generic types used in entities. I reported a bug in hibernate-core (Jira), which was fixed as part of spring boot 3.2.1 (hibternate 6.4.1) but now my jpa repositories are the next ones, that are not happy with my implementation.
Lets assume we have 2 abstract classes Parent and Child, that know each other
And we have multiple implementations of them
The ids of the parents are not specified in the abstract class cause i need different generation strategies depending on the specific type.
And then we have a repository interface for children, all specific-type-repositories are inheriting:
I will work with this ChildRepository in an abstract service.
If i try to execute the "extistsByIdAndParentId" method, i'll get the following exception
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the given name [id] on this ManagedType [com.hibernate.data.core.Parent]
But this kind of inheritance worked in my previous version using spring boot version 2.6.1
I've attached a application of this simplified usecase, where you can recreate my problem
spring-data.zip
Thanks!
Denis
The text was updated successfully, but these errors were encountered: