Skip to content

Conversation

@gavinking
Copy link
Member

@gavinking gavinking commented Dec 18, 2025

Really, getSingleResult() is saying there should be a single element in getResultList(). If that's not the case, you should use select distinct.

That said, we might want a way to recover the old behavior (H5, apparently) of making things distinct in memory according to equals(). Though, actually, I believe you can just use a ResultListTransformer for that. Perhaps we should just add a built-in one for migration purposes.

[Please describe here what your change is about]


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


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

…f "same"

Really, getSingleResult() is saying there should be a single element in
getResultList(). If that's not the case, you should use 'select distinct'.

That said, we might want a way to recover the old behavior (H5, apparently)
of making things distinct in memory according to equals(). Though, actually,
I believe you can just use a ResultListTransformer for that. Perhaps we
should just add a built-in one for migration purposes.
@gavinking gavinking marked this pull request as ready for review December 18, 2025 11:53
@gavinking gavinking requested a review from sebersole December 18, 2025 11:53
@gavinking
Copy link
Member Author

@sebersole WDYT of this?

Copy link
Member

@beikov beikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good change, but depending on what the behavior of ORM 5.x was, we might want to either backport this or add a migration guide note.

Imagine what would happen if you do e.g. select e.someIntField from MyEntity e and call getSingleResult(). This would have succeeded if all values are the same with ORM 6.x and 7.x, but now start to fail. Not saying that such errors would be wrong, just that we have to be careful.

@gavinking
Copy link
Member Author

Imagine what would happen if you do e.g. select e.someIntField from MyEntity e and call getSingleResult(). This would have succeeded if all values are the same with ORM 6.x and 7.x, but now start to fail. Not saying that such errors would be wrong, just that we have to be careful.

The trouble is that right now this can succeed or fail depending on the JDBC driver. On h2, I got Integer values being canonicalized, and passing, but on Postgres the same code failed. Pretty ugly.

@gavinking
Copy link
Member Author

add a migration guide note.

We definitely need to do that. For sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants