开发者

Problem with Hibernate findById

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(Re开发者_运维百科strictions.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 ?


"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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜