org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2

Atlassian JIRA | Alejandro Conde Carrillo | 2 years ago
  1. 0

    Sometimes, when renaming users in a external directory, a new user is created, instead of updating the current one. This causes a duplicity in the pair external_id and directory_id which cause an exception when calling the method {{com.atlassian.confluence.user.crowd.CachedCrowdUserDao.findByExternalId}} which is used during authentication and synchronization of the external directory. The error resulting from that operation is: {noformat}org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2 at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:590) at org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:353) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:375) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:337) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindUserByExternalId(HibernateUserDao.java:501) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindByExternalId(HibernateUserDao.java:473) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.findByExternalId(HibernateUserDao.java:449) at com.atlassian.confluence.user.crowd.CachedCrowdUserDao.findByExternalId(CachedCrowdUserDao.java:164) ...{noformat} This affects embedded Crowd so other Atlassian applications (Confluence, JIRA,...) may also have this problem.

    Atlassian JIRA | 2 years ago | Alex Conde [Atlassian]
    org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2
  2. 0

    In the table cwd_user, there should be no rows where the _external_id_ is repeated for the same _directory_id_. Said in another way, the _external_id_ should be unique for the same _directory_id_. To avoid this from causing problems, we should add a unique constraint at a database level in the table _cwd_user_. When two users share _external_id_ and _directory_id_, the user is not able to login or update new information from the external user directory. Those actions will fail with the following error: {noformat}org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2 at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:590) at org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:353) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:375) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:337) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindUserByExternalId(HibernateUserDao.java:501) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindByExternalId(HibernateUserDao.java:473) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.findByExternalId(HibernateUserDao.java:449) at com.atlassian.confluence.user.crowd.CachedCrowdUserDao.findByExternalId(CachedCrowdUserDao.java:164) ...{noformat} This also affects embedded Crowd.

    Atlassian JIRA | 3 years ago | Alex Conde [Atlassian]
    org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2
  3. 0

    Sometimes, when renaming users in a external directory, a new user is created, instead of updating the current one. This causes a duplicity in the pair external_id and directory_id which cause an exception when calling the method {{com.atlassian.confluence.user.crowd.CachedCrowdUserDao.findByExternalId}} which is used during authentication and synchronization of the external directory. The error resulting from that operation is: {noformat}org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2 at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:590) at org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:353) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:375) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:337) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindUserByExternalId(HibernateUserDao.java:501) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindByExternalId(HibernateUserDao.java:473) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.findByExternalId(HibernateUserDao.java:449) at com.atlassian.confluence.user.crowd.CachedCrowdUserDao.findByExternalId(CachedCrowdUserDao.java:164) ...{noformat} This affects embedded Crowd so other Atlassian applications (Confluence, JIRA,...) may also have this problem.

    Atlassian JIRA | 2 years ago | Alejandro Conde Carrillo
    org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    In the table cwd_user, there should be no rows where the _external_id_ is repeated for the same _directory_id_. Said in another way, the _external_id_ should be unique for the same _directory_id_. To avoid this from causing problems, we should add a unique constraint at a database level in the table _cwd_user_. When two users share _external_id_ and _directory_id_, the user is not able to login or update new information from the external user directory. Those actions will fail with the following error: {noformat}org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2 at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:590) at org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:353) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:375) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:337) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindUserByExternalId(HibernateUserDao.java:501) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindByExternalId(HibernateUserDao.java:473) at com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.findByExternalId(HibernateUserDao.java:449) at com.atlassian.confluence.user.crowd.CachedCrowdUserDao.findByExternalId(CachedCrowdUserDao.java:164) ...{noformat} This also affects embedded Crowd.

    Atlassian JIRA | 3 years ago | Alejandro Conde Carrillo
    org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2
  6. 0

    My Project Name: AAAA My Chain Name: AAAA In one instance I tried to update an existing job to have the name AAAA. I got a validation error. I should theoretically be able to name my plan like this shouldn't I? During an attempt to reproduce the above behaviour, I tried to create a _new_ Job with the name AAAA. This submitted successfully. However now I get a whole bunch of other exceptions: {code} 2010-09-30 10:17:41,755 ERROR [1638360365@qtp-1196121930-6] [FiveOhOh] 500 Exception was thrown. org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2 at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:590) at org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:353) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:375) at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:337) at com.atlassian.bamboo.plan.PlanHibernateDao.getPlanByName(PlanHibernateDao.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) {code} The getPlanByName method only looks at the project name and plan name in the build table. And hence will return both the chain and the job. So we need to either a) prevent people from creating jobs with the same name as a plan (though this behaves the opposite to how we handle the keys) b) fix the getPlanByName method, and any other use cases which die because of the duplication.

    Atlassian JIRA | 6 years ago | Brydie McCoy [Atlassian]
    org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. org.springframework.dao.IncorrectResultSizeDataAccessException

      query did not return a unique result: 2

      at org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException()
    2. Hibernate
      HibernateTemplate.execute
      1. org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:590)
      2. org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:353)
      3. org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:375)
      4. org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:337)
      4 frames
    3. com.atlassian.crowd
      HibernateUserDao.findByExternalId
      1. com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindUserByExternalId(HibernateUserDao.java:501)
      2. com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.internalFindByExternalId(HibernateUserDao.java:473)
      3. com.atlassian.crowd.embedded.hibernate2.HibernateUserDao.findByExternalId(HibernateUserDao.java:449)
      3 frames
    4. com.atlassian.confluence
      CachedCrowdUserDao.findByExternalId
      1. com.atlassian.confluence.user.crowd.CachedCrowdUserDao.findByExternalId(CachedCrowdUserDao.java:164)
      1 frame