SonarQube
  1. SonarQube
  2. SONAR-2329

NonUniqueResultException occurs when analyzing both a maven module and its parent

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.8
    • Component/s: Database, Maven Plugin
    • Labels:
      None
    • Number of attachments :
      0

      Description

      let's take a simple example :

      • project 1
        • module A
        • module B

      Running those simple steps allow to reproduce this issue :

      • analyse module A
      • analyse project 1
      • analyse module A -> KO

        Issue Links

          Activity

          Hide
          Joachim Van der Auwera added a comment -

          How can I remove the project? It seems some of the projects don't have project roles assigned to them which means that admin account does not see the "delete" button on the settings page or the "project roles" link in the menu etc.

          Show
          Joachim Van der Auwera added a comment - How can I remove the project? It seems some of the projects don't have project roles assigned to them which means that admin account does not see the "delete" button on the settings page or the "project roles" link in the menu etc.
          Hide
          Freddy Mallet added a comment -

          Hi Joachim, you can also directly update the 'islast' column to '0' on involved snapshots. That will fix the issue.

          Show
          Freddy Mallet added a comment - Hi Joachim, you can also directly update the 'islast' column to '0' on involved snapshots. That will fix the issue.
          Hide
          Freddy Mallet added a comment -

          While waiting for Sonar 2.8, here is the SQL request to execute in order to remove those "duplications":

          *MySQL

          update snapshots old_snap, snapshots new_snap set old_snap.islast=0 where old_snap.islast=1 and new_snap.created_at > old_snap.created_at and new_snap.project_id = old_snap.project_id and new_snap.islast=1
          

          *Oracle

          update sonar.snapshots old_snap set old_snap.islast=0 where islast=1 and exists(select * from sonar.snapshots new_snap where new_snap.created_at > old_snap.created_at and new_snap.project_id = old_snap.project_id and new_snap.islast=1)
          
          Show
          Freddy Mallet added a comment - While waiting for Sonar 2.8, here is the SQL request to execute in order to remove those "duplications": *MySQL update snapshots old_snap, snapshots new_snap set old_snap.islast=0 where old_snap.islast=1 and new_snap.created_at > old_snap.created_at and new_snap.project_id = old_snap.project_id and new_snap.islast=1 *Oracle update sonar.snapshots old_snap set old_snap.islast=0 where islast=1 and exists(select * from sonar.snapshots new_snap where new_snap.created_at > old_snap.created_at and new_snap.project_id = old_snap.project_id and new_snap.islast=1)
          Hide
          Samuel Langlois added a comment -

          Thank you for the workaround, it works fine.

          Here it is for PostgreSQL:

          update snapshots old_snap set islast=false where islast=true and exists(select * from snapshots new_snap where new_snap.created_at > old_snap.created_at and new_snap.project_id = old_snap.project_id and new_snap.islast=true)
          
          Show
          Samuel Langlois added a comment - Thank you for the workaround, it works fine. Here it is for PostgreSQL: update snapshots old_snap set islast= false where islast= true and exists(select * from snapshots new_snap where new_snap.created_at > old_snap.created_at and new_snap.project_id = old_snap.project_id and new_snap.islast= true )
          Hide
          Marcel Schutte added a comment -

          Just upgrading to 2.8 didn't resolve this issue. I had to run the above update query to get things working. Before running the query I got the following exception:

          Caused by: javax.persistence.NonUniqueResultException: Expected single result, but got : [Snapshot[resourceId=1148,createdAt=2011-04-29 23:08:23.0,version=01.01.01.1054-SNAPSHOT,last=true,status=P,scope=PRJ,path=,depth=0,qualifier=TRK,rootId=<null>,parentId=<null>,rootProjectId=1148,period1Mode=previous_analysis,period2Mode=days,period3Mode=days,period4Mode=<null>,period5Mode=<null>,period1Param=2011-04-19,period2Param=5,period3Param=30,period4Param=<null>,period5Param=<null>,period1Date=2011-04-19 05:06:16.0,period2Date=2011-04-24 23:08:23.0,period3Date=2011-03-30 23:08:23.0,period4Date=<null>,period5Date=<null>,id=486870], Snapshot[resourceId=1148,createdAt=2011-05-04 09:52:04.0,version=01.01.01.1054-SNAPSHOT,last=true,status=P,scope=PRJ,path=495746.,depth=1,qualifier=BRC,rootId=495746,parentId=495746,rootProjectId=1149,period1Mode=previous_analysis,period2Mode=days,period3Mode=days,period4Mode=<null>,period5Mode=<null>,period1Param=2011-04-29,period2Param=5,period3Param=30,period4Param=<null>,period5Param=<null>,period1Date=2011-04-29 23:08:23.0,period2Date=2011-04-29 09:52:04.0,period3Date=2011-04-04 09:52:04.0,period4Date=<null>,period5Date=<null>,id=495748]]
          at org.sonar.jpa.session.JpaDatabaseSession.getSingleResult(JpaDatabaseSession.java:194)
          at org.sonar.jpa.session.JpaDatabaseSession.getSingleResult(JpaDatabaseSession.java:212)
          at org.sonar.batch.ProjectBuilder.isLatestAnalysis(ProjectBuilder.java:114)
          at org.sonar.batch.ProjectBuilder.configure(ProjectBuilder.java:91)
          at org.sonar.batch.ProjectBuilder.configure(ProjectBuilder.java:86)
          at org.sonar.batch.ProjectTree.start(ProjectTree.java:97)
          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)
          at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110)
          ... 35 more

          Show
          Marcel Schutte added a comment - Just upgrading to 2.8 didn't resolve this issue. I had to run the above update query to get things working. Before running the query I got the following exception: Caused by: javax.persistence.NonUniqueResultException: Expected single result, but got : [Snapshot [resourceId=1148,createdAt=2011-04-29 23:08:23.0,version=01.01.01.1054-SNAPSHOT,last=true,status=P,scope=PRJ,path=,depth=0,qualifier=TRK,rootId=<null>,parentId=<null>,rootProjectId=1148,period1Mode=previous_analysis,period2Mode=days,period3Mode=days,period4Mode=<null>,period5Mode=<null>,period1Param=2011-04-19,period2Param=5,period3Param=30,period4Param=<null>,period5Param=<null>,period1Date=2011-04-19 05:06:16.0,period2Date=2011-04-24 23:08:23.0,period3Date=2011-03-30 23:08:23.0,period4Date=<null>,period5Date=<null>,id=486870] , Snapshot [resourceId=1148,createdAt=2011-05-04 09:52:04.0,version=01.01.01.1054-SNAPSHOT,last=true,status=P,scope=PRJ,path=495746.,depth=1,qualifier=BRC,rootId=495746,parentId=495746,rootProjectId=1149,period1Mode=previous_analysis,period2Mode=days,period3Mode=days,period4Mode=<null>,period5Mode=<null>,period1Param=2011-04-29,period2Param=5,period3Param=30,period4Param=<null>,period5Param=<null>,period1Date=2011-04-29 23:08:23.0,period2Date=2011-04-29 09:52:04.0,period3Date=2011-04-04 09:52:04.0,period4Date=<null>,period5Date=<null>,id=495748] ] at org.sonar.jpa.session.JpaDatabaseSession.getSingleResult(JpaDatabaseSession.java:194) at org.sonar.jpa.session.JpaDatabaseSession.getSingleResult(JpaDatabaseSession.java:212) at org.sonar.batch.ProjectBuilder.isLatestAnalysis(ProjectBuilder.java:114) at org.sonar.batch.ProjectBuilder.configure(ProjectBuilder.java:91) at org.sonar.batch.ProjectBuilder.configure(ProjectBuilder.java:86) at org.sonar.batch.ProjectTree.start(ProjectTree.java:97) 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) at org.picocontainer.lifecycle.ReflectionLifecycleStrategy.invokeMethod(ReflectionLifecycleStrategy.java:110) ... 35 more
          Hide
          Freddy Mallet added a comment -

          Hi Marcel, if a duplication already exists in the Sonar DB, Sonar 2.8 doesn't automatically fix the issue and the above SQL request needs to be manually executed. But Sonar 2.8 prevents such duplications to appear.

          Show
          Freddy Mallet added a comment - Hi Marcel, if a duplication already exists in the Sonar DB, Sonar 2.8 doesn't automatically fix the issue and the above SQL request needs to be manually executed. But Sonar 2.8 prevents such duplications to appear.
          Hide
          Peter Merikan added a comment -

          and here is the sql for MS SQL Server

          update snapshots 
          set snapshots.islast = 0  
          where snapshots.islast = 1 
          and exists(select * from snapshots new_snap 
                      where new_snap.created_at > snapshots.created_at 
                      and new_snap.project_id = snapshots.project_id 
                      and new_snap.islast = 1)
          
          Show
          Peter Merikan added a comment - and here is the sql for MS SQL Server update snapshots set snapshots.islast = 0 where snapshots.islast = 1 and exists( select * from snapshots new_snap where new_snap.created_at > snapshots.created_at and new_snap.project_id = snapshots.project_id and new_snap.islast = 1)
          Hide
          Laurent Grangeau added a comment -

          It seems that since Sonar 2.9, the bug reappeared...

          Show
          Laurent Grangeau added a comment - It seems that since Sonar 2.9, the bug reappeared...
          Hide
          Freddy Mallet added a comment -

          Hi Laurent, please describe your use case ? If your DB was already corrupted before the migration you first need to execute a SQL request.
          Thanks
          Freddy

          Show
          Freddy Mallet added a comment - Hi Laurent, please describe your use case ? If your DB was already corrupted before the migration you first need to execute a SQL request. Thanks Freddy
          Hide
          Laurent Grangeau added a comment -

          Hi Freddy,

          I have made a migration from Sonar 2.8 to Sonar 2.9, and the exception appears after this migration.
          I executed the workaround and it works for me.

          But I was forced to execute it 4 or 5 times before the DB was fully functionnal.

          Show
          Laurent Grangeau added a comment - Hi Freddy, I have made a migration from Sonar 2.8 to Sonar 2.9, and the exception appears after this migration. I executed the workaround and it works for me. But I was forced to execute it 4 or 5 times before the DB was fully functionnal.
          Hide
          Freddy Mallet added a comment -

          FYI Laurent, you're the second user to get this error so I guess something has been broken. I'll keep you informed.

          Show
          Freddy Mallet added a comment - FYI Laurent, you're the second user to get this error so I guess something has been broken. I'll keep you informed.
          Hide
          Freddy Mallet added a comment -

          Hi Laurent, in fact only one other user has reported this issue on Sonar 2.9 and this was finally due to Sonar 2.8. So I'm not opening another JIRA ticket. Have you faced this issue another time after your first fix ?
          Thanks

          Show
          Freddy Mallet added a comment - Hi Laurent, in fact only one other user has reported this issue on Sonar 2.9 and this was finally due to Sonar 2.8. So I'm not opening another JIRA ticket. Have you faced this issue another time after your first fix ? Thanks
          Hide
          Laurent Grangeau added a comment -

          Hi Freddy,

          I've faced this issue 2 or 3 times after my first fix, but now, it seems to work again with no exception...
          I'll inform you if this error appears again.

          Show
          Laurent Grangeau added a comment - Hi Freddy, I've faced this issue 2 or 3 times after my first fix, but now, it seems to work again with no exception... I'll inform you if this error appears again.
          Hide
          philippe tseyen added a comment -

          I just upgraded from sonar 2.6 to 2.9 and I'm facing the issue as well.

          I'm going to try out the sql statements mentioned above now.

          Show
          philippe tseyen added a comment - I just upgraded from sonar 2.6 to 2.9 and I'm facing the issue as well. I'm going to try out the sql statements mentioned above now.
          Hide
          Bill Neff added a comment -

          I upgraded from sonar 2.5 to sonar 2.9 and have repeatedly fixed the issue using the sql statements above, only to have it reappear. We have dozens of projects, and it does not happen with every build, but happens sporadically across most of our projects, roughly once or twice a day.

          Show
          Bill Neff added a comment - I upgraded from sonar 2.5 to sonar 2.9 and have repeatedly fixed the issue using the sql statements above, only to have it reappear. We have dozens of projects, and it does not happen with every build, but happens sporadically across most of our projects, roughly once or twice a day.
          Hide
          Freddy Mallet added a comment -

          Hi Bill, in that case, please start a new thread of discussion in the Sonar user mailing. Indeed, the root cause can't be the same and we need to figure out what happens. Thanks

          Show
          Freddy Mallet added a comment - Hi Bill, in that case, please start a new thread of discussion in the Sonar user mailing. Indeed, the root cause can't be the same and we need to figure out what happens. Thanks
          Hide
          John Schrantz added a comment -

          Hi there, I am having the same issue with 2.9. We have run the above script multiple times and it seems to work every time, but the exception randomly comes back. I tried searching for a new ticket and looked in the mailing list for any discussion, but I haven't found anything.

          So is there a new bug for 2.9 or somewhere else I should be looking for updates to this issue?

          Show
          John Schrantz added a comment - Hi there, I am having the same issue with 2.9. We have run the above script multiple times and it seems to work every time, but the exception randomly comes back. I tried searching for a new ticket and looked in the mailing list for any discussion, but I haven't found anything. So is there a new bug for 2.9 or somewhere else I should be looking for updates to this issue?
          Hide
          Raghunathan Semburakkiannan added a comment -

          I'm using Derby inbuilt DB coming along with sonar stand-alone version), I'm wondering, can any one suggest me the fix/work-around?

          Show
          Raghunathan Semburakkiannan added a comment - I'm using Derby inbuilt DB coming along with sonar stand-alone version), I'm wondering, can any one suggest me the fix/work-around?
          Hide
          Freddy Mallet added a comment -

          Hi John, the only known open bug/limitation which can lead to such duplication is SONAR-2761.

          Show
          Freddy Mallet added a comment - Hi John, the only known open bug/limitation which can lead to such duplication is SONAR-2761 .
          Hide
          Pau Garcia i Quiles added a comment -

          Raghunathan,

          Probably too late but the query for Derby is:

          update sonar.snapshots old_snap set islast=false where islast=true and exists(select * from sonar.snapshots new_snap where new_snap.created_at > old_snap.created_at and new_snap.project_id = old_snap.project_id and new_snap.islast=true)

          Show
          Pau Garcia i Quiles added a comment - Raghunathan, Probably too late but the query for Derby is: update sonar.snapshots old_snap set islast=false where islast=true and exists(select * from sonar.snapshots new_snap where new_snap.created_at > old_snap.created_at and new_snap.project_id = old_snap.project_id and new_snap.islast=true)
          Hide
          DK added a comment -

          Hi,

          I'm hitting this issue in Sonar 3.1.1. Like the description I'm running sonar on a multi-module Maven project.
          I run sonar on a top level pom and also on a child pom.

          Show
          DK added a comment - Hi, I'm hitting this issue in Sonar 3.1.1. Like the description I'm running sonar on a multi-module Maven project. I run sonar on a top level pom and also on a child pom.
          Hide
          Freddy Mallet added a comment -

          Please send an email to the Sonar User mailing list @DK with the Sonar analysis log file. Indeed I'm pretty sure that you're not facing exactly the same issue.

          Show
          Freddy Mallet added a comment - Please send an email to the Sonar User mailing list @DK with the Sonar analysis log file. Indeed I'm pretty sure that you're not facing exactly the same issue.
          Hide
          Toni Menzel added a comment -

          We are hitting this again with Sonar v.3.2. Will open an extra ticket cause @Freddy suggest its "pretty sure.. not exactly the same issue in 3.1"

          Show
          Toni Menzel added a comment - We are hitting this again with Sonar v.3.2. Will open an extra ticket cause @Freddy suggest its "pretty sure.. not exactly the same issue in 3.1"
          Hide
          Freddy Mallet added a comment -

          Hi @Toni, just send an email to the Sonar mailing list and I'll take care to try understanding what happens. When I say "pretty sure.. not exactly the same issue .." I'm not saying that the Sonar user is lying or that the exception can't appear anymore, I'm just saying that the root cause of the exception is not what we fixed with this JIRA ticket and so we must first fully undertand what other root cause can lead to get the same exception.
          Thanks

          Show
          Freddy Mallet added a comment - Hi @Toni, just send an email to the Sonar mailing list and I'll take care to try understanding what happens. When I say "pretty sure.. not exactly the same issue .." I'm not saying that the Sonar user is lying or that the exception can't appear anymore, I'm just saying that the root cause of the exception is not what we fixed with this JIRA ticket and so we must first fully undertand what other root cause can lead to get the same exception. Thanks
          Hide
          David Campos added a comment -

          This is still happening with Sonar 3.4.1 and two projects that, while sharing the groupId, differ on artifactIds

          Sample:

          Project1: org.sample:module1:1.0.1-SNAPSHOT
          Project2: org.sample.module12:1.0.4-SNAPSHOT

          If both projects are located at different maven projects and compiled/analysed at the same time (eg: nightly builds) the issue appears.

          Obviously the workaround works... until the next periodical analysis is triggered.

          Show
          David Campos added a comment - This is still happening with Sonar 3.4.1 and two projects that, while sharing the groupId, differ on artifactIds Sample: Project1: org.sample:module1:1.0.1-SNAPSHOT Project2: org.sample.module12:1.0.4-SNAPSHOT If both projects are located at different maven projects and compiled/analysed at the same time (eg: nightly builds) the issue appears. Obviously the workaround works... until the next periodical analysis is triggered.
          Hide
          Freddy Mallet added a comment -

          @David, please open a dedicated thread on the Sonar User mailing list because I'm pretty sure that's your issue doesn't relate to this ticket. Thanks

          Show
          Freddy Mallet added a comment - @David, please open a dedicated thread on the Sonar User mailing list because I'm pretty sure that's your issue doesn't relate to this ticket. Thanks
          Hide
          Jose Sa added a comment -

          This is still causing problems in 3.7

          11:21:59 [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar (default-cli) on project csi-for-interfaces-webui-sonar: Can not execute SonarQube analysis: Unable to execute Sonar: Expected single result, but got : [Snapshot[resourceId=487,buildDate=2013-11-21 13:12:28.0,createdAt=2013-11-21 13:12:28.0,version=DYNAMIC-SNAPSHOT,last=true,status=P,purgeStatus=1,scope=PRJ,path=5169742.,depth=1,qualifier=BRC,rootId=5169742,parentId=5169742,rootProjectId=478,period1Mode=previous_analysis,period2Mode=days,period3Mode=previous_version,period4Mode=<null>,period5Mode=<null>,period1Param=<null>,period2Param=30,period3Param=1.5,period4Param=<null>,period5Param=<null>,period1Date=<null>,period2Date=2013-10-22 13:12:28.0,period3Date=2013-11-21 13:12:52.0,period4Date=<null>,period5Date=<null>,id=5169751], Snapshot[resourceId=487,buildDate=2013-11-21 13:12:52.0,createdAt=2013-11-21 13:12:52.0,version=1.5,last=true,status=P,purgeStatus=<null>,scope=PRJ,path=5169827.,depth=1,qualifier=BRC,rootId=5169827,parentId=5169827,rootProjectId=28490,period1Mode=previous_analysis,period2Mode=days,period3Mode=previous_version,period4Mode=<null>,period5Mode=<null>,period1Param=2013-11-21,period2Param=30,period3Param=DYNAMIC-SNAPSHOT,period4Param=<null>,period5Param=<null>,period1Date=2013-11-21 00:05:20.0,period2Date=2013-10-22 13:12:52.0,period3Date=2013-11-21 00:05:20.0,period4Date=<null>,period5Date=<null>,id=5169828]] -> [Help 1]
          

          The SQL workaround provided does seem to fix it temporarily.

          Should we re-open this case or open a new issue ?

          Show
          Jose Sa added a comment - This is still causing problems in 3.7 11:21:59 [ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.1:sonar ( default -cli) on project csi- for -interfaces-webui-sonar: Can not execute SonarQube analysis: Unable to execute Sonar: Expected single result, but got : [Snapshot[resourceId=487,buildDate=2013-11-21 13:12:28.0,createdAt=2013-11-21 13:12:28.0,version=DYNAMIC-SNAPSHOT,last= true ,status=P,purgeStatus=1,scope=PRJ,path=5169742.,depth=1,qualifier=BRC,rootId=5169742,parentId=5169742,rootProjectId=478,period1Mode=previous_analysis,period2Mode=days,period3Mode=previous_version,period4Mode=< null >,period5Mode=< null >,period1Param=< null >,period2Param=30,period3Param=1.5,period4Param=< null >,period5Param=< null >,period1Date=< null >,period2Date=2013-10-22 13:12:28.0,period3Date=2013-11-21 13:12:52.0,period4Date=< null >,period5Date=< null >,id=5169751], Snapshot[resourceId=487,buildDate=2013-11-21 13:12:52.0,createdAt=2013-11-21 13:12:52.0,version=1.5,last= true ,status=P,purgeStatus=< null >,scope=PRJ,path=5169827.,depth=1,qualifier=BRC,rootId=5169827,parentId=5169827,rootProjectId=28490,period1Mode=previous_analysis,period2Mode=days,period3Mode=previous_version,period4Mode=< null >,period5Mode=< null >,period1Param=2013-11-21,period2Param=30,period3Param=DYNAMIC-SNAPSHOT,period4Param=< null >,period5Param=< null >,period1Date=2013-11-21 00:05:20.0,period2Date=2013-10-22 13:12:52.0,period3Date=2013-11-21 00:05:20.0,period4Date=< null >,period5Date=< null >,id=5169828]] -> [Help 1] The SQL workaround provided does seem to fix it temporarily. Should we re-open this case or open a new issue ?
          Hide
          Freddy Mallet added a comment -

          @Jose, if my understanding is correct you're facing the following issue : SONAR-4692

          Show
          Freddy Mallet added a comment - @Jose, if my understanding is correct you're facing the following issue : SONAR-4692
          Hide
          Jose Sa added a comment -

          Yes there are common modules of different parents.

          Show
          Jose Sa added a comment - Yes there are common modules of different parents.

            People

            • Assignee:
              Simon Brandhof
              Reporter:
              Freddy Mallet
            • Votes:
              1 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: