Sonar's "result returns more than one elements"

We have been hitting the dreaded Sonar error lately, resulting in constantly broken Hudson builds:

Caused by: javax.persistence.NonUniqueResultException: result returns more than one elements

The only workaround I could find was Pti’s database clean up. Doing this manually was a pain, especially after coming back from holidays, when a couple of weeks of records had been created.

So I have come up with a quick JRuby script to semi-automate this. And here is how to use it:

  • Save this script in clean_sonar.rb,
  • Update the Sonar database details with the correct values,
  • Download mysql connector jar, and save it in the same folder as your ruby script,
  • Backup your database,
  • Make sure your database backup is ok,
  • Check again (I guess you’re now warned),
  • Run the script as follows:
$ jruby clean_sonar.rb

And here is the (quick’n‘dirty) script.

 
---

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

---