Database Corruption - query did not return a unique result
症状
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)
原因
Somehow there were 2 projects added with the same Project_key (might be a result of a strange double click).
ソリューション
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 |
Project_ID is being used in two tables: BUILD and BUILDRESULTSUMMARY_LABEL.
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);
- 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.
- Stop your Bamboo server, and make sure that you have backed up your Bamboo database before making any changes to the DB.
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;
- Start your Bamboo server.