useEmma = openjpa.isInUse() ? false : true

OpenJPA is a lightweight JPA framework — leaner than Hibernate and well-regarded for its performance characteristics. A key part of how it achieves this is the enhancer: a post-processor that modifies the bytecode of persistent classes to enable lazy loading and efficient dirty tracking. Crucially, it preserves line numbers and maintains debugger compatibility.

I’m a strong advocate for EMMA as a code coverage tool. Compared to Clover, it’s free, fast, and has minimal memory overhead. On one project, nightly CI jobs were crashing under Clover — switching to EMMA fixed it outright.

The Problem

Unfortunately, OpenJPA’s enhancer and EMMA’s instrumentor don’t play well together. Both tools modify bytecode at the class level, and when they run on the same classes the output is incomplete or incorrect coverage data. You can’t have both doing their thing on the same codebase without conflict.

Your Options

Option 1: Switch to Cobertura or Clover Cobertura instruments using a different approach and doesn’t conflict with OpenJPA. Clover is commercial but robust. Either sidesteps the incompatibility entirely.

Option 2: Filter JPA classes from coverage If you’d rather keep EMMA, exclude DAO and JPA entity classes from coverage analysis. You lose visibility into those classes, but everything else stays clean and the tool runs without conflict.

The right call depends on how much you rely on coverage metrics for DAO/entity classes specifically. In most projects I’ve worked on, the business logic (where coverage matters most) lives outside the entity layer anyway — so Option 2 is often perfectly acceptable.