Hi there,
I'm having issues with getting proper query results using DISTINCT_ROOT_ENTITY. My query is as following:
detachedCriteria.add(Restrictions.in(idField, ids)); detachedCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List objects = getHibernateTemplate().findByCriteria(detachedCriteria);
Reason for using the Restrictions.in construction is that I want to be able to limit the number of root objects. The query above is part of a larger retrieve() function.
The issue here is that the objects that are retrieved contain Lists of other referenced objects. The count of these referenced objects is not correct.
Inspecting the query shows me that an left outer join is used to gather that data. When executing the query directly in Oracle I receive 42 rows. When Hibernate has executed the query the list with referenced objects contains 42 objects as well. The strange thing here is that all of these objects have the same object reference, so its the same data. Which is correct, because there only exists one definition of those in the database.
I suspect that either the join type that is used is not correct; or that the DISTINCT_ROOT_ENTITY does not properly merge the rows into objects. This last one sounds the most plausible, since all objects in the list actually have the same object reference - and thus are the same.
I use Hibernate v3.3.2 within Equinox OSGi with Spring.
Any ideas or pointers? Thanks!
|