Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Object Relational Mapping and the fly likes Criteria.list() returns more objects than expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria.list() returns more objects than expected" Watch "Criteria.list() returns more objects than expected" New topic
Author

Criteria.list() returns more objects than expected

Jan Hruby
Greenhorn

Joined: Apr 22, 2009
Posts: 4
Hi all,

I have such a problem, that my application returns more identical objects but I want to get only one. This thing happens when I use join formula in my sql statement. When I execute this statement result set has of course more rows beacuse of a join formula. But I want Hibernate to convert it in a single object which owns a list of other objects. Eventually I get such an object but it's copied x times (x stands for resultset row count) in a resulting list.

I'll be thankfull for any suggestion

hbm.xml:


list() method:



other classes:
Jan Hruby
Greenhorn

Joined: Apr 22, 2009
Posts: 4
This solved my problem with more identical root objects.

criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
Randeep Singh Arora
Greenhorn

Joined: May 14, 2010
Posts: 6
I want to try this scenario can you please send me source code for your problem.

 
 
subject: Criteria.list() returns more objects than expected