Database Corruption - query did not return a unique result

Still need help?

The Atlassian Community is here for you.

Ask the community

Symptoms

After unsuccessful cloning of a plan (by creating a new project), Bamboo gives an error message every time a user tries to work with that project:

2012-03-06 14:01:11,147 WARN [qtp2583282-18] [HibernateObjectDao] Unable to get project with key MYKEY
net.sf.hibernate.NonUniqueResultException: query did not return a unique result: 2
    at net.sf.hibernate.impl.AbstractQueryImpl.uniqueElement(AbstractQueryImpl.java:559)
    at net.sf.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:385)
    at com.atlassian.bamboo.project.ProjectHibernateDao$4.doInHibernate(ProjectHibernateDao.java:90)
    at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:370)
    at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:337)
    at com.atlassian.bamboo.project.ProjectHibernateDao.getProjectByKey(ProjectHibernateDao.java:82)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)

Cause

Somehow there were 2 projects added with the same Project_key (might be a result of a strange double click).

Resolution

  1. After running this SQL query, we find out the involved "PROJECT_ID"s:

    select * from PROJECT where PROJECT_KEY ='MYKEY';
    
    |PROJECT_ID|CREATED_DATE           |UPDATED_DATE           |PROJECT_KEY|TITLE      |DESCRIPTION|MARKED_FOR_DELETION|
    ---------------------------------------------------------------------------------------------------------------------
    |10420225  |2012-03-05 15:48:03.697|2012-03-05 15:48:03.697|MYKEY      |My Feedback|           |0                  |
    |10420226  |2012-03-05 15:48:03.710|2012-03-05 15:48:03.710|MYKEY      |My Feedback|           |0                  |

     

  2. Project_ID is being used in two tables: BUILD and BUILDRESULTSUMMARY_LABEL.

  3. In order to find out which row should be deleted (the one that isn't linked from any of those tables), run these SQL queries to check if there are any rows that don't have a matching Project_ID:

    select * from buildresultsummary_label where project_id not in (select project_id from Project);
    select * from build where project_id not in (select project_id from Project);
  4. After getting the results of the previous queries, you should be able to tell which one is linked(this should stay) and which one isn't(needs to be removed). If none of the rows are linked, you can delete the second one by following the next steps.
  5. Stop your Bamboo server, and make sure that you have backed up your Bamboo database before making any changes to the DB.
  6. Make sure that you have a backup of your Bamboo DB and run this SQL query to delete the row that isn't linked (or the second row):

    DELETE from PROJECT where PROJECT_ID=10420226;
  7. Start your Bamboo server.


Last modified on Dec 31, 2019

Was this helpful?

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