Make CriteriaImpl.uniqueResult() more robust
--------------------------------------------
Key: HHH-5034
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5034
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.3.1
Reporter: Tomas Pollak
We are using Sybase for generating a query that has a COUNT(*) and ORDER BY. Granted, the
'order by' doesn't have any semantic effect, but it's a dynamically
generated query, and we need to know the total count as well as the actual result.
The problem is that Sybase returns many rows for such a query, and the uniqueResult()
fails with a NonUniqueResultException. Although every returned row contains an Integer
with the same value, they are different instances.
We could modify the AbstractQueryImpl.uniqueElement(List list) as follows:
static Object uniqueElement(List list) {
int size = list.size();
if (size == 0) return null;
Object first = list.get(0);
for (int i = 1; i < size; i++) {
if (!safeEquals(first, list.get(i))) {
throw new NonUniqueResultException(list.size());
}
}
return first;
}
static boolean safeEquals(Object first, Object second) {
if (first instanceof Integer && second instanceof Integer) {
return ((Integer)first).compareTo((Integer)second) == 0;
}
return first == second;
}
That would solve our issue.
Thanks.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira