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-15802 ubQuery with "in" results in java.lang.ClassCastException: class org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl cannot be cast to class org.hibernate.metamodel.mapping.EntityValuedModelPart #5800
Conversation
… class org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl cannot be cast to class org.hibernate.metamodel.mapping.EntityValuedModelPart
I don't think that we should support this. IMO it was a bug that this worked before. |
Why shouldn't this be supported? If not, then you should adjust the API (data types) that this is not possible anymore (so you get an compile time error). In with subquery is perfect valid SQL. I know no other ways to build such queries with the criteria API (without using HQL etc). |
Try using the static metamodel and then you will see a compile error: criteria.where(root.get(Participation_.id).in(subQuery)); |
That is exactly what I reported in the original issue (https://hibernate.atlassian.net/jira/software/c/projects/HHH/issues/HHH-15802) and that works with 5.6.14 AND 6.1.6 (but I get a runtime error >=6.1.1). Look at https://github.com/csware/si if you want to see yourself in a full project. |
Hmm, the |
Removing the .get part works for me and would be a solution (added that workaround to the issue). |
Let's please not call it a workaround, as it's the proper way to do the comparison you are aiming for. You surely understand that comparing apples with oranges simply isn't the right thing to do. Most statically typed programming languages will not allow to comparing objects with values and I think nobody should rely on something like that. |
There are still other places in current Hibernate (>= 6.1.1) where this still works:
The only difference seems to be that the subQuery.select is "multivalued". It is at least inconsistent ATM. |
I have no strong opinion on this, but it's definitely wrong that the user experiences a |
Closing this in favor of #6189 since we will rather make sure we drop support for this unsafe error prone comparison of entity valued paths against basic valued paths/literals |
is it documented in the migration guide? |
https://hibernate.atlassian.net/browse/HHH-15802