Unannotated entity attributes require a Transient annotation

In OpenJPA, attributes that are themselves entity classes are not persisted by default. EclipseLink has a different default behavior and tries to persist these attributes to the database. To keep the OpenJPA behavior of ignoring unannotated entity attributes, add the javax.persistence.Transient annotation to these attributes in EclipseLink.

This rule flags attributes with no JPA annotations that are entity classes. If the tool cannot find the referenced class, it logs a warning in the Eclipse error log. The tool might not find the class if dependent projects or classes are not accessible or there are compilation errors. An automated fix will add the @Transient annotation to the attribute.

In the following entity class, the entityReference field is flagged by the rule.

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

@Entity
public class EntityA {
    @Id
    private int id;
   
    private EntityB entityReference;
}
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class EntityB {
    @Id
    private int id;
}

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

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

@Entity
public class EntityA {
    @Id
    private int id;
   
    @Transient
    private EntityB entityReference;
}

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