Resaving a repository in Bamboo throws an error 'query did not return unique result'

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Bamboo shows an error message stating "query did not return a unique result: 2" when trying to re-save a repository from the Bamboo Overview > Linked repositories.

Environment

The problem was observed in Bamboo version 8.1. However, it's important to note that there's a possibility of this issue occur in newer versions as well.

Diagnosis

This error can be seen in the Bamboo User Interface or found in the <bamboo-home>/logs/atlassian-bamboo.log file:

org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2; 
    nested exception is org.hibernate.NonUniqueResultException: query did not return a unique result: 2
	at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:225)
	at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:370)
	at org.springframework.orm.hibernate5.HibernateTemplate.execute(HibernateTemplate.java:320)
	at com.atlassian.bamboo.repository.RepositoryDefinitionHibernateDao.findLinkedRepositoryByName(RepositoryDefinitionHibernateDao.java:407)
	at com.atlassian.bamboo.repository.RepositoryDefinitionManagerImpl.getLinkedRepositoryByName(RepositoryDefinitionManagerImpl.java:292)

Cause

The issue might happen when a linked repository, originated from an older Bamboo version, was flagged for deletion in the database but wasn't successfully removed.

Solution

  1. Access the Get Repository REST API endpoint and search for any repository with the same name. This is an example you can use with curl:

    curl --request GET \
      --url 'https://{bamboo-base-url}/rest/api/latest/repository?searchTerm=<repositoryName>' \
      --header 'Accept: application/json'

    Change <repositoryName> to the same name of the repository in the UI that is getting the query did not return a unique result error.

  2. If the GET request returns any repository, access the URL from the GET output and change the name of the repository so it would be a unique one.

    Sample output
    {
       "size":1,
       "searchResults":[
          {
             "id":134316033,
             "name":"Repository",
             "url":"http://{bamboo-base-url}/admin/configureLinkedRepositories.action?repositoryId=134316033",
             "rssEnabled":true
          }
       ],
       "start-index":0,
       "max-result":1
    }

    In this example the URL would be http://{bamboo-base-url}/admin/configureLinkedRepositories.action?repositoryId=134316033.

  3. Try to rename the repository which it was throwing the error once again.

Last modified on Nov 6, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.