On 04/28/2010 08:57 AM, Bala Nair wrote:
Hi all,
  I'm new to RHQ development and have run into an issue using the CLI to test alert definition filtering.  I am able to get a list of all alert defs returned from AlertDefinitionManager.findAlertDefinitionsByCriteria(new AlertDefinitionCriteria()), but when I try to set a condition in the criteria I get an exception or an empty result set.  I traced the code execution as far as the bolded line below - the call to getSingleResult in CriteriaQueryRunner.execute() and then it drops into hibernate code.  I'm not familiar with hibernate or how the object mapping works between the AlertDefinitionCriteria members and the filter overrides, but it strikes me as significant that I'm seeing a cast exception when I try to filter by parent id which is an integer in the db but a string in the AlertDefintionCriteria.  Any help would be appreciated.  TIA.

Bala Nair

Filter by parent id:

rhqadmin@192.168.209.93:7780$ var c1 = new AlertDefinitionCriteria()

rhqadmin@192.168.209.93:7780$ c1.addFilterAlertTemplateParentId(0)

rhqadmin@192.168.209.93:7780$ AlertDefinitionManager.findAlertDefinitionsByCriteria(c1)

[Warning] javax.ejb.EJBException: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
Bela, the issue is that AlertDefinitionCriteria was mapping that filter field to a String type, but it actually refers to an Integer in the underlying data model.  This issue was documented here[1] and I've already pushed a fix to master (git hash 303467aeda8d90b48cb68581d53211c774a82fd5).  Thanks for finding this.

-joseph

[1] - https://bugzilla.redhat.com/show_bug.cgi?id=586918 (AlertDefinitionCriteria throws ClassCastException if filterAlertTemplateParentId / filterAlertTemplateResourceTypeId is set)