org.hibernate.NonUniqueResultException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • It is possible for duplicate entries to exist in HipChat Server's _crowd_ database tables, leading to failed synchronizations with external user directories. h3. Environment * HipChat Server v1.3.4 or v1.3.7 * Configured to synchronize with an external user directory (LDAP, Crowd, Active Directory, etc.) h3. Steps to Reproduce The steps to reproduce the root cause of this behavior are not currently known. h3. Expected Results Synchronization with external user directory is successful. h3. Actual Results Synchronization with the external directory fails, as reflected at {{Server admin >> Directory}}. h5. Scenario 1 - duplicate row in _cwd_membership_ The below exception is thrown in the _/home/admin/logs/atlassian-crowd.log_ file: *com.atlassian.crowd.dao.membership.MembershipDAOHibernate.findInternalMembership* {noformat} 2015-12-03 09:51:06,437 scheduler_Worker-4 ERROR [atlassian.crowd.directory.DbCachingDirectoryPoller] Error occurred while refreshing the cache for directory [ 393217 ]. org.hibernate.NonUniqueResultException: query did not return a unique result: 2 at org.hibernate.internal.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:918) at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:396) at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.findInternalMembership(MembershipDAOHibernate.java:370) at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.isUserDirectMember(MembershipDAOHibernate.java:213) at com.atlassian.crowd.directory.AbstractInternalDirectory.isUserDirectGroupMember(AbstractInternalDirectory.java:893) at com.atlassian.crowd.directory.AbstractInternalDirectory.removeUserFromGroup(AbstractInternalDirectory.java:945) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.removeUserMembershipsForGroup(DbCachingRemoteChangeOperations.java:812) at sun.reflect.GeneratedMethodAccessor170.invoke(Unknown Source) {noformat} h5. Scenario 2 - duplicate row in _cwd_user_ The below exception is thrown in the _/home/admin/logs/atlassian-crowd.log_ file: *com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId* {noformat} 2016-01-28 17:50:02,838 scheduler_Worker-5 ERROR [atlassian.crowd.directory.DbCachingDirectoryPoller] Error occurred while refreshing the cache for directory [ 425985 ]. org.hibernate.NonUniqueResultException: query did not return a unique result: 2 at org.hibernate.internal.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:918) at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:396) at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:213) at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:55) at com.atlassian.crowd.directory.AbstractInternalDirectory.findUserByExternalId(AbstractInternalDirectory.java:182) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.userByExternalIdOrNull(DbCachingRemoteChangeOperations.java:293) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.updateUsers(DbCachingRemoteChangeOperations.java:233) at sun.reflect.GeneratedMethodAccessor464.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) {noformat} h3.Workaround A workaround exists for this behavior, but may require direct database modification. Please [contact HipChat Server Support| https://support.atlassian.com/servicedesk/customer/portal/31] for assistance.
    via by Shayne Covey [Atlassian],
  • It is possible for duplicate entries to exist in HipChat Server's _crowd_ database tables, leading to failed synchronizations with external user directories. h3. Environment * HipChat Server v1.3.4 or v1.3.7 * Configured to synchronize with an external user directory (LDAP, Crowd, Active Directory, etc.) h3. Steps to Reproduce The steps to reproduce the root cause of this behavior are not currently known. h3. Expected Results Synchronization with external user directory is successful. h3. Actual Results Synchronization with the external directory fails, as reflected at {{Server admin >> Directory}}. h5. Scenario 1 - duplicate row in _cwd_membership_ The below exception is thrown in the _/home/admin/logs/atlassian-crowd.log_ file: *com.atlassian.crowd.dao.membership.MembershipDAOHibernate.findInternalMembership* {noformat} 2015-12-03 09:51:06,437 scheduler_Worker-4 ERROR [atlassian.crowd.directory.DbCachingDirectoryPoller] Error occurred while refreshing the cache for directory [ 393217 ]. org.hibernate.NonUniqueResultException: query did not return a unique result: 2 at org.hibernate.internal.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:918) at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:396) at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.findInternalMembership(MembershipDAOHibernate.java:370) at com.atlassian.crowd.dao.membership.MembershipDAOHibernate.isUserDirectMember(MembershipDAOHibernate.java:213) at com.atlassian.crowd.directory.AbstractInternalDirectory.isUserDirectGroupMember(AbstractInternalDirectory.java:893) at com.atlassian.crowd.directory.AbstractInternalDirectory.removeUserFromGroup(AbstractInternalDirectory.java:945) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.removeUserMembershipsForGroup(DbCachingRemoteChangeOperations.java:812) at sun.reflect.GeneratedMethodAccessor170.invoke(Unknown Source) {noformat} h5. Scenario 2 - duplicate row in _cwd_user_ The below exception is thrown in the _/home/admin/logs/atlassian-crowd.log_ file: *com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId* {noformat} 2016-01-28 17:50:02,838 scheduler_Worker-5 ERROR [atlassian.crowd.directory.DbCachingDirectoryPoller] Error occurred while refreshing the cache for directory [ 425985 ]. org.hibernate.NonUniqueResultException: query did not return a unique result: 2 at org.hibernate.internal.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:918) at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:396) at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:213) at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:55) at com.atlassian.crowd.directory.AbstractInternalDirectory.findUserByExternalId(AbstractInternalDirectory.java:182) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.userByExternalIdOrNull(DbCachingRemoteChangeOperations.java:293) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.updateUsers(DbCachingRemoteChangeOperations.java:233) at sun.reflect.GeneratedMethodAccessor464.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) {noformat} h3.Workaround A workaround exists for this behavior, but may require direct database modification. Please [contact HipChat Server Support| https://support.atlassian.com/servicedesk/customer/portal/31] for assistance.
    via by Shayne Covey [Atlassian],
  • GitHub comment 229#167136122
    via GitHub by ppazos
    ,
  • Crowd is querying {{cwd_user}} by {{external_id}} and is expecting unique results *for users*. There is no unique constraint on this column and in some conditions a crowd sync can cause duplicate {{external_id}} to be entered into the table. Stack trace: {noformat:title=atlassian-stash.log} 2015-05-13 02:37:56,086 ERROR [clusterScheduler_Worker-9] c.a.c.d.DbCachingDirectoryPoller Error occurred while refreshing the cache for directory [ 32770 ]. org.hibernate.NonUniqueResultException: query did not return a unique result: 2 at org.hibernate.internal.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:975) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final] at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:402) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final] at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:211) ~[crowd-persistence-hibernate4-2.8.2-m5.jar:na] at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:55) ~[crowd-persistence-hibernate4-2.8.2-m5.jar:na] ... {noformat} A fix should first check and remove duplicates that are orphaned from {{cwd_membership}}, then any remaining duplicate users, before creating the unique constraint. h4. Workaround This can be manually fixed by deleting duplicate entries. It appears that the bad entries are missing a corresponding entry in {{cwd_membership}}, but this may not be true for all cases. https://confluence.atlassian.com/display/STASHKB/Unable+to+sync+crowd+user+directory+-+query+did+not+return+a+unique+result h4. Fix Stash 3.10 applies a new unique constraint to the relevant columns in the {{cwd_user}} table to ensure data consistency. If there are duplicate {{(directory_id, external_id)}} pairs when the system is upgraded to 3.10, they will be automatically repaired as part of upgrading. This fix cannot be applied on SQL Server 2005. Due to limitations in SQL Server 2005, it is not possible to create a unique constraint or unique index on {{(directory_id, external_id)}} because external_id can be {{NULL}}. *As a result, support for SQL Server 2005 is now deprecated*. Stash will continue to run on SQL Server 2005, but this constraint will not be applied. As a result, it's possible instances running against SQL Server 2005 may continue to fail. Support for SQL Server 2005 will be fully removed in Stash 4.0. Administrators with Stash instances using SQL Server 2005 will be required to either update their SQL Server to 2008 or newer, or migrate to another supported database. Any instance still running on SQL Server 2005 will be unable to start after upgrading to 4.0. After upgrading to 3.10, the exact failure described here is no longer possible. However, it may be possible for LDAP synchronization to fail if the new constraint is violated. Anyone whose instance encounters such a failure is encouraged to open a support request and provide details on the error. (This failure is very unlikely, but I want to note it here in case it does happen.)
    via by James Gorman,
  • Crowd is querying {{cwd_user}} by {{external_id}} and is expecting unique results *for users*. There is no unique constraint on this column and in some conditions a crowd sync can cause duplicate {{external_id}} to be entered into the table. Stack trace: {noformat:title=atlassian-stash.log} 2015-05-13 02:37:56,086 ERROR [clusterScheduler_Worker-9] c.a.c.d.DbCachingDirectoryPoller Error occurred while refreshing the cache for directory [ 32770 ]. org.hibernate.NonUniqueResultException: query did not return a unique result: 2 at org.hibernate.internal.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:975) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final] at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:402) ~[hibernate-core-4.3.8.Final.jar:4.3.8.Final] at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:211) ~[crowd-persistence-hibernate4-2.8.2-m5.jar:na] at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:55) ~[crowd-persistence-hibernate4-2.8.2-m5.jar:na] ... {noformat} A fix should first check and remove duplicates that are orphaned from {{cwd_membership}}, then any remaining duplicate users, before creating the unique constraint. h4. Workaround This can be manually fixed by deleting duplicate entries. It appears that the bad entries are missing a corresponding entry in {{cwd_membership}}, but this may not be true for all cases. https://confluence.atlassian.com/display/STASHKB/Unable+to+sync+crowd+user+directory+-+query+did+not+return+a+unique+result h4. Fix Stash 3.10 applies a new unique constraint to the relevant columns in the {{cwd_user}} table to ensure data consistency. If there are duplicate {{(directory_id, external_id)}} pairs when the system is upgraded to 3.10, they will be automatically repaired as part of upgrading. This fix cannot be applied on SQL Server 2005. Due to limitations in SQL Server 2005, it is not possible to create a unique constraint or unique index on {{(directory_id, external_id)}} because external_id can be {{NULL}}. *As a result, support for SQL Server 2005 is now deprecated*. Stash will continue to run on SQL Server 2005, but this constraint will not be applied. As a result, it's possible instances running against SQL Server 2005 may continue to fail. Support for SQL Server 2005 will be fully removed in Stash 4.0. Administrators with Stash instances using SQL Server 2005 will be required to either update their SQL Server to 2008 or newer, or migrate to another supported database. Any instance still running on SQL Server 2005 will be unable to start after upgrading to 4.0. After upgrading to 3.10, the exact failure described here is no longer possible. However, it may be possible for LDAP synchronization to fail if the new constraint is violated. Anyone whose instance encounters such a failure is encouraged to open a support request and provide details on the error. (This failure is very unlikely, but I want to note it here in case it does happen.)
    via by James Gorman,
  • Problem while Retreiving the value from DB
    via by Parthiban Malayandi,
    • org.hibernate.NonUniqueResultException: query did not return a unique result: 2 at org.hibernate.internal.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:918) at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:396) at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:213) at com.atlassian.crowd.dao.user.UserDAOHibernate.findByExternalId(UserDAOHibernate.java:55) at com.atlassian.crowd.directory.AbstractInternalDirectory.findUserByExternalId(AbstractInternalDirectory.java:182) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.userByExternalIdOrNull(DbCachingRemoteChangeOperations.java:293) at com.atlassian.crowd.directory.DbCachingRemoteChangeOperations.updateUsers(DbCachingRemoteChangeOperations.java:233) at sun.reflect.GeneratedMethodAccessor464.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)

    Users with the same issue

    Unknown User
    3 times, last one,
    Unknown visitor1 times, last one,