hbm2ddl and cobertura (sonar)

We use Sonar to handle code metrics for our projects.  Recently, we upgraded our stack to the latest and greatest of Spring, Spring MVC and all things Hibernate.  We are using hibernate annotations to create our database schema and dbunit to populate our test data.  We run the sonar plugin (maven) nightly to provide metrics.

After getting our annotations all happy and working properly, our sonar plugin started to fail.

Cobertura: Loaded information on 257 classes.
Instrumenting 257 files to /myproject/target/generated-classes/cobertura
Cobertura: Saved information on 257 classes.
Instrument time: 2083ms
17:47:14,153 INFO org.hibernate.cfg.annotations.Version - Hibernate Annotations 3.4.0.GA
17:47:14,160 INFO org.hibernate.cfg.Environment - Hibernate 3.3.1.GA
17:47:14,163 INFO org.hibernate.cfg.Environment - hibernate.properties not found
17:47:14,165 INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
17:47:14,166 INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
17:47:14,202 INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.1.0.GA
Configuration XML file loaded: file:/myproject/src/main/resources/hibernate.cfg.xml
17:47:14,203 INFO org.hibernate.cfg.Configuration - configuring from url: file:/myproject/src/main/resources/hibernate.cfg.xml
BUILD ERROR
Can not execute Sonar
Embedded error: Unable to execute maven plugin
myproject.domain.Address

I found this link which cleared up the entire thing.

I needed to add a cobertura dependency to the hibernate plugin in my pom.xml.

I also realized that a new version of Sonar came available last week. I upgraded!

DBUnit with MSSQL and Maven2

We ran into a couple of problems using the maven dbunit plugin.  We have used it on several projects before, but always with MySQL.

Some things to look out for.

  • We used jailer to dump an existing test database out to a dbunit flatfile.  Make sure that in your plugin configuration you set the “format” to “flat”.
  • On our previous operations we used “CLEAN_INSERT” this time we needed “MSSQL_CLEAN_INSERT” in order to avoid this error “Cannot insert explicit value for identity column in table ‘tablename’ when IDENTITY_INSERT is set to OFF”