Bug 1030031 - NonUniqueResultException thrown from AlertDefinitionManagerBean
NonUniqueResultException thrown from AlertDefinitionManagerBean
Status: NEW
Product: RHQ Project
Classification: Other
Component: Core Server (Show other bugs)
4.9
Unspecified Unspecified
unspecified Severity unspecified (vote)
: ---
: ---
Assigned To: RHQ Project Maintainer
Mike Foley
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-11-13 13:34 EST by Elias Ross
Modified: 2013-11-18 15:02 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Elias Ross 2013-11-13 13:34:22 EST
Description of problem:

Unclear how this is happening. Could have been the result of 

18:30:17,213 ERROR [org.rhq.enterprise.server.resource.group.definition.GroupDefinitionManagerBean] (RHQScheduler_Worker-3) Error recalculating DynaGroups for GroupDefinition[id=
10181]: javax.ejb.EJBTransactionRolledbackException: Could not create group alert definition children for Resources [451187, 470672, 482123, 482166, 482219, 482295, 482414] under
 ResourceGroup[id=14246]
...
Caused by: org.rhq.enterprise.server.alert.AlertDefinitionCreationException: Could not create group alert definition children for Resources [451187, 470672, 482123, 482166, 48221
9, 482295, 482414] under ResourceGroup[id=14246]
....
Caused by: javax.persistence.NonUniqueResultException: result returns more than one elements
        at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:293) [hibernate-entitymanager-4.2.0.CR1.jar:4.2.0.CR1]
        at org.rhq.enterprise.server.alert.AlertDefinitionManagerBean.fixRecoveryId(AlertDefinitionManagerBean.java:318) [rhq-server.jar:4.9.0]
        at org.rhq.enterprise.server.alert.AlertDefinitionManagerBean.createAlertDefinitionInternal(AlertDefinitionManagerBean.java:262) [rhq-server.jar:4.9.0]
        at org.rhq.enterprise.server.alert.AlertDefinitionManagerBean.createAlertDefinitionInNewTransaction(AlertDefinitionManagerBean.java:217) [rhq-server.jar:4.9.0]        at sun.reflect.GeneratedMethodAccessor137.invoke(Unknown Source) [:1.6.0_38]


Version-Release number of selected component (if applicable): 4.9


How reproducible: Every time the dynagroup is recomputed


Steps to Reproduce:
1. Unclear
2.
3.

Actual results:


Expected results:


Additional info:
Comment 1 Elias Ross 2013-11-18 15:02:18 EST
Simple patch:

diff --git a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerBean.java b/modules/enterprise/server/jar/src/main/java/org/rhq/ent
index 330eb0d..3330141 100644
--- a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerBean.java
+++ b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/alert/AlertDefinitionManagerBean.java
@@ -302,8 +302,11 @@ private void fixRecoveryId(AlertDefinition definition) {
                 fixRecoveryIdQuery.setParameter("resourceId", definition.getResource().getId());
                 // definition.recoveryId current points at the toBeRecovered template, we want the definition
                 fixRecoveryIdQuery.setParameter("parentId", definition.getRecoveryId()); // wrong one to be replaced
-                Integer correctRecoveryId = (Integer) fixRecoveryIdQuery.getSingleResult();
-                definition.setRecoveryId(correctRecoveryId);
+                List<Integer> resultList = fixRecoveryIdQuery.getResultList();
+                if (!resultList.isEmpty()) {
+                    Integer correctRecoveryId = resultList.get(0);
+                    definition.setRecoveryId(correctRecoveryId);
+                }
             } else if (definition.getGroupAlertDefinition() != null && definition.getRecoveryId() != 0) {
                 // so we need to set the resource-level recovery id properly
                 String findCorrectRecoveryId = "" //
@@ -315,8 +318,11 @@ private void fixRecoveryId(AlertDefinition definition) {
                 fixRecoveryIdQuery.setParameter("resourceId", definition.getResource().getId());
                 // definition.recoveryId current points at the toBeRecovered template, we want the definition
                 fixRecoveryIdQuery.setParameter("groupAlertDefinitionId", definition.getRecoveryId()); // wrong one to be replaced
-                Integer correctRecoveryId = (Integer) fixRecoveryIdQuery.getSingleResult();
-                definition.setRecoveryId(correctRecoveryId);
+                List<Integer> resultList = fixRecoveryIdQuery.getResultList();
+                if (!resultList.isEmpty()) {
+                    Integer correctRecoveryId = resultList.get(0);
+                    definition.setRecoveryId(correctRecoveryId);
+                }
             }
         } catch (NoResultException nre) {
             // expected when the recovery ids have already been fixed

Note You need to log in before you can comment on or make changes to this bug.