goashok / hibernate-generic-dao

Automatically exported from code.google.com/p/hibernate-generic-dao
0 stars 0 forks source link

HibernateSearchProcessor.count: query did not return a unique result #74

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I have a table with two entries
2. A native SQL: SELECT count(*) FROM PUBLIC.USERPROFILE WHERE GENDER LIKE 
'MALE' works (result "2")
3. When calling HibernateSearchProcessor.count I get the below stack trace
(HSQL: select count(*) as col_0_0_ from USERPROFILE userprofil0_ where 
userprofil0_.GENDER=?)

What version of the product are you using? On what operating system?
0.5.1

Please provide any additional information below.

Caused by: org.hibernate.NonUniqueResultException: query did not return a 
unique result: 2
    at org.hibernate.impl.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:868)
    at org.hibernate.impl.AbstractQueryImpl.uniqueResult(AbstractQueryImpl.java:859)
    at com.trg.search.hibernate.HibernateSearchProcessor.count(HibernateSearchProcessor.java:136)
    at com.trg.dao.hibernate.HibernateBaseDAO._count(HibernateBaseDAO.java:526)
    at com.trg.dao.hibernate.GenericDAOImpl.count(GenericDAOImpl.java:49)

Is it right, hat you use uniqueResult here?

Original issue reported on code.google.com by ralf.eic...@gmail.com on 17 Nov 2010 at 8:46

GoogleCodeExporter commented 9 years ago
the above error just araises when I call dao.count(search) directly.
When I call indirectly (see snippet), it works:

    @Override
    public int count(ISearch search) {
        // return dao.count(search);
        SearchResult<T> searchResult = dao.searchAndCount(search);
        return searchResult.getTotalCount();
    }

As I need the count separate from the results, this workaround means executing 
the search twice, which is a dirty solution.
But it shows that there is no general problem with my data or hibernate 
mapping...

So it looks like a real issue.

Original comment by ralf.eic...@gmail.com on 18 Nov 2010 at 6:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I know it's been a while, but do you have any way of 1) getting us a way to 
reproduce this error and/or 2) getting us the HQL query that is used by 
searchAndCount (since this works and the HQL query you posted for just search 
did not work, it would be helpful to contrast the two.)

Original comment by dwolvert on 27 Feb 2011 at 11:04

GoogleCodeExporter commented 9 years ago
the problem is solved: my fault. the table did not have a unique constraint and 
therefore two identical entries were in table... so the result could not be 
unique...

Original comment by ralf.eic...@gmail.com on 8 Oct 2012 at 12:50

GoogleCodeExporter commented 9 years ago
Thanks, ralf.eichinger. Issue closed.

Original comment by dwolvert on 8 Oct 2012 at 3:01