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

org.qlrm.mapper.JpaResultMapper cannot deal properly with unique results #9

Closed
JanMosigItemis opened this Issue Jan 28, 2016 · 2 comments

Comments

Projects
None yet
3 participants
@JanMosigItemis
Contributor

JanMosigItemis commented Jan 28, 2016

Thank you very much for this neat little mapping helper. Unfortunately I might have found a bug:

I have the following situation:

Query query = entityManager.createQuery("SELECT COUNT (e) FROM Entity e;");

This query will result in a uniqe Long as a result.
When calling jpaMapper.list(query, Long.class), this results in a ClassCastException.
This is also the case when calling jpaMapper.uniqueResult(query, Long.class).

The reason for this is that in the described situation

  • query.getResultList does return a List that contains a Long, not an Array of Long with one member.
  • query.getSingleResult does return a Long, not an Array of Long with one member.

A possible fix might be to post process the returned results so that it is guaranteed that a cast to Object[] will succeed.

JanMosigItemis added a commit to JanMosigItemis/qlrm that referenced this issue Jan 28, 2016

simasch added a commit that referenced this issue Jan 28, 2016

Merge pull request #10 from JanMosigItemis/master
Issue #9: Implemented post processing for raw JPA result data

@simasch simasch closed this Jan 28, 2016

@nicolaMaza

This comment has been minimized.

Show comment
Hide comment
@nicolaMaza

nicolaMaza Jun 9, 2016

@simasch @JanMosigItemis
I think is useless adding this cyclic procedure every time and for the entire result.
If the issue affects only the queries which returning one element, we can add this workaround to the post processing method:
if (rawResults.size() == 1) {
for (Object rawResult : rawResults) {
result.add(postProcessSingleResult(rawResult));
}
} else {
result = (List<Object[]>) rawResults;
}
What do you think?
Nicola

nicolaMaza commented Jun 9, 2016

@simasch @JanMosigItemis
I think is useless adding this cyclic procedure every time and for the entire result.
If the issue affects only the queries which returning one element, we can add this workaround to the post processing method:
if (rawResults.size() == 1) {
for (Object rawResult : rawResults) {
result.add(postProcessSingleResult(rawResult));
}
} else {
result = (List<Object[]>) rawResults;
}
What do you think?
Nicola

@simasch

This comment has been minimized.

Show comment
Hide comment
@simasch

simasch Jun 9, 2016

Owner

sounds resonable

Owner

simasch commented Jun 9, 2016

sounds resonable

nicolaMaza pushed a commit to nicolaMaza/qlrm that referenced this issue Jun 13, 2016

simasch added a commit that referenced this issue Jun 13, 2016

Merge pull request #14 from nicolaMaza/master
issue #9: post-processing method workaround for unique results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment