problem with ResourceTypeCriteria

John Mazzitelli mazz at redhat.com
Sat Oct 23 15:30:31 UTC 2010


I seem to have discovered a very bad problem with ResourceTypeCriteria 
and/or the Criteria Query engine. I may need Joe to help with this one.

I discovered this while stepping through ResourceTypeRepository, 
specifically:

ResourceTypeRepository.getResourceTypes(Integer[], 
EnumSet<MetadataType>, TypesLoadedCallback)

where the Integer[] array has a single ID (my Linux Platform type ID) 
and the EnumSet contains MetadataType.operations, measurements, events, 
and resourceConfigurationDefinition.

This boils down to a call to:

resourceTypeService.findResourceTypesByCriteria(criteria)

where my criteria has filterId null but filterIds is a one-element List 
(I suspect the problem might be caused by using the 
ResourceTypeCriteria.addFilterIds (plural) rather than the singlular 
addFilterId form).

When I get back the results, the PageList has *48* resource types in the 
list - ALL are the Linux Platform type. I should only have received *1* 
back (remember, I only asked for 1 resource type, and the criteria's 
filterIds had only a single item in it). There must be something wrong 
with the dynamically built query that caused it to return 48 rows, as 
opposed to just 1.

Note that if I do NOT ask for any MetadataType (i.e. the EnumSet is 
empty, thus I just ask for the base ResourceType without any 
relationship collections), things work fine and the fetch by criteria 
returns a single item in the PageList as expected.

Debugging in the CriteriaQueryRunner, I see this as the query:

SELECT resourcetype
FROM ResourceType resourcetype
LEFT JOIN FETCH resourcetype.resourceConfigurationDefinition
LEFT JOIN FETCH resourcetype.metricDefinitions
LEFT JOIN FETCH resourcetype.eventDefinitions
LEFT JOIN FETCH resourcetype.operationDefinitions
WHERE ( resourcetype.id in ( :ids ) )

and this is the countQuery:

SELECT COUNT(resourcetype)
FROM ResourceType resourcetype
WHERE ( resourcetype.id in ( :ids ) )

the named parameter list looked correct, the "ids" appeared to only have 
a single Id in it. But stepping in:

org.rhq.enterprise.server.util.CriteriaQueryRunner.execute()

and I see the query results come back with 48 rows but the countQuery 
returns back with 1 (and 1 is what should be correct).

So, the countQuery returns the correct answer - 1 - but the query itself 
returns 48 items!

Very odd. For some reason, hibernate returned us 48 times the data than 
we expected. Unsure what we did wrong in building the query.


More information about the rhq-devel mailing list