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-17956 Criteria multiselect ignores type of the criteria query and always returns list of Object[] #8247
base: main
Are you sure you want to change the base?
Conversation
0f890cd
to
ac4cae6
Compare
@beikov please also consider what happens with the following code: var query = factory.getCriteriaBuilder().createQuery(String[].class);
var bookRoot = query.from(Book.class);
query.multiselect(bookRoot.get("isbn"), bookRoot.get("title"), bookRoot.get("pages"));
var resultList = entityManager.createQuery(query).getResultList(); This should throw a meaningful error stating that If we're going to allow this sort of thing, then we need to check upfront that the type of the This was previously not necessary because we assumed that the array type was always |
A second item of feedback is: even the javadoc of
And I don't think primitive arrays make sense because it's pretty hard for us to validate that a Furthermore, it seems that the support for primitive arrays is leading to most of the complexity in this PR. If support for primitive arrays were removed, I guess this would be a whole lot simpler, no? |
If users requests an
Of course handling primitive arrays requires more code, but I think it's useful and our session with @franz1981 has shown that performance is not an issue, so we might as well do it IMO. EDIT: ... requires more code to be efficient, ... |
It seems to me that the complexity/usefulness ratio here is really quite high. |
} | ||
else { | ||
throw new IllegalArgumentException( "Criteria has multiple query roots" ); | ||
if ( getQueryString() == CRITERIA_HQL_STRING ) { |
Check warning
Code scanning / CodeQL
Reference equality test on strings Warning
@@ -298,7 +271,12 @@ | |||
|
|||
private void validateStatement(SqmStatement<R> sqmStatement, Class<R> resultType) { | |||
if ( sqmStatement instanceof SqmSelectStatement<?> ) { | |||
SqmUtil.verifyIsSelectStatement( sqmStatement, hql ); | |||
final SqmQueryPart<R> queryPart = ( (SqmSelectStatement<R>) sqm ).getQueryPart(); | |||
if ( hql == CRITERIA_HQL_STRING ) { |
Check warning
Code scanning / CodeQL
Reference equality test on strings Warning
… always returns list of Object[]
https://hibernate.atlassian.net/browse/HHH-17956