Entity objects with constructors must also have a default constructor

When a Java Persistence API (JPA) entity class has a constructor with arguments, the class must also have a default, no-argument constructor. The OpenJPA implementation automatically generates the no-argument constructor, but the EclipseLink implementation does not.

This rule scans for entity classes with the @Entity or @MappedSuperclass annotations. Entity classes with constructors that do not also have a no-argument constructor are flagged. The automated fix will add an empty no-argument constructor to the class.

For example, the rule flags the following entity class:

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class MissingNoArgConstructorEntity {
    @Id
    private int id;

    public MissingNoArgConstructorEntity(int id) {
        this.id = id;
    }
}

The automated fix will add the no-argument constructor:

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class MissingNoArgConstructorEntity {
    @Id
    private int id;

    public MissingNoArgConstructorEntity() {
    }
    
    public MissingNoArgConstructorEntity(int id) {
        this.id = id;
    } 
}

For information about this issue and other OpenJPA to EclipseLink migration issues, see the OpenJPA to EclipseLink JPA Migration: Mappings guide.