tags:

views:

37

answers:

1

have a peculiar problem with hibernate. I have a hibernate function like this.

@SuppressWarnings("unchecked")
public List<AppResponse> findByResponseId(long requestId) {
  return (List<AppResponse>) jdbcReference.getSessionFactory().getCurrentSession()
        .createCriteria(AppResponse.class).add(Restrictions.eq("requestId",requestId))
        .list();
 }

And this is supposed to return a list with 4 "AppResponses" for requestId=say '1234'. The function as expected returns a list with four AppResponse objects.But the problem is all 4 objects represent the same row. I dont get 4 different objects(one per row). Has anyone encountered such a issue.? What could be the problem ?

+2  A: 

"id" makes me think "primary key". You should not be returning a list of anything in that case - it's either a unique object or nothing.

Your "1234" sounds like a candidate key that didn't make the primary key cut. It should have an index and be extracted using a query with a WHERE clause.

UPDATE: Did you override equals and hashCode properly? When you say they represent the same row, it suggests to me that either you've got duplicate data in your table (nothing unique about the objects beyond the "id" you cite) or you didn't implement equals and hashCode correctly.

duffymo
Simple.Hibernate translates the above as SELECT COLUMN LISTS FROM APPRESPONSES WHERE REQUEST_ID=?. The query is correct and it should return more than rows.
chedine
I figured it out. It is my mistake. I have mentioned the wrong field as PK.
chedine