ElementCollection annotations must be accompanied by a defined Column annotation

When an attribute is annotated with @ElementCollection, a separate table is created for the attribute that includes the attribute ID and value. In OpenJPA, the column for the annotated attribute is named element, whereas EclipseLink names the column based on the name of the attribute. To remain compatible with tables that were created with OpenJPA, add an @Column annotation with the name attribute set to element.

This rule scans for @ElementCollection annotations that do not have the @Column annotation with a name attribute. An automated fix will add a @Column annotation or edits an existing @Column annotation that does not have a name attribute.

For example, the rule flags the @ElementCollection annotation in the following field access entity class because it does not have a @Column annotation.

import java.util.List;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class ElementCollectionEntity {
    
    @Id
    private int id;
    
    @ElementCollection
    private List<String> listofStrings;
}

An automated fix will add the @Column annotation.

import java.util.List;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class ElementCollectionEntity {
    
    @Id
    private int id;
    
    @ElementCollection
    @Column(name = "element")
    private List<String> listofStrings;
}

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