Allowed parameter Java types #3937
Replies: 3 comments 15 replies
-
I think this is perfectly fine if we do believe that the code you've just shown is "actually bad". OTOH, I also think it's fine to treat a "small" number of numeric types specially. Almost all programming languages have hardcoded implicit conversions between numeric types, and I do actually thinks that's reasonable. As an example, I would find it very convenient if Hibernate implicitly converted But I would distinguish this from anything more open-ended. I think numeric types are a special case. |
Beta Was this translation helpful? Give feedback.
-
What do you mean by "historically"? I just tried this example with the current state of main i.e. 5.5.0-SNAPSHOT and it does not work. I get:
|
Beta Was this translation helpful? Give feedback.
-
@sebersole can this be closed now? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Historically Hibernate allowed binding parameters with "mismatched" java types. E.g., given the legacy HQL
Animal
:#bodyWeight
is defined as Float, but here we try to bind an Integer. Previous versions allowed this. At the moment, on 6.0, this fails because we are expecting a Float, not an Integer.We had discussed this previously and decided to not allow that, but I believe it was just on Zulip. Wanted to document this decision for posterity.
This new behavior is consistent with loading an entity. Assuming an entity has a Long id,
session.get( TheEntity.class, 1 )
will fail even on older versions.Beta Was this translation helpful? Give feedback.
All reactions