Unannotated collection attributes require a Transient annotation

In OpenJPA, attributes that inherit from the java.util.Collection<E> interface are not a default persistent type, so these attributes are not persisted unless they are annotated. EclipseLink has a different default behavior and attempts to persist these attributes to the database. To keep the OpenJPA behavior of ignoring unannotated collection attributes, add the javax.persistence.Transient annotation to these attributes in EclipseLink.

This rule flags attributes with no JPA annotations that inherit from the java.util.Collection<E> interface, including the following subinterfaces:

In the following entity class, the collectionField and the listField attributes are flagged by the rule.

import java.util.Collection;
import java.util.List;

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

@Entity
public class UnannotatedCollectionEntity {
    @Id
    private int id;
   
    private Collection collectionField;
    private List listField;

}

An automated fix will add the @Transient annotations and the import statement.

import java.util.Collection;
import java.util.List;

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

@Entity
public class UnannotatedCollectionEntity {
    @Id
    private int id;
   
    @Transient
    private Collection collectionField;
    @Transient
    private List listField;

}

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