Embedded classes must be annotated as embeddable

According to the Java Persistence API (JPA) specification, if an entity embeds a class by using an Embedded annotation, the embeddable class must be annotated with an Embeddable annotation, not an Entity annotation. In OpenJPA, when an attribute is annotated with the @Embedded annotation but the referenced class is annotated with an @Entity annotation instead of an @Embeddable annotation, OpenJPA treats this class as an embeddable by embedding this class into other entities as well as treating this class as an entity by creating a table for the class. EclipseLink throws an exception under these circumstances since a class can be either an entity or an embeddable.

This rule scans for @Embedded annotations that reference classes that are annotated with @Entity. The rule flags annotations depending on the scope of the scan and if all related classes are found.

In this example, the rule flags the @Entity annotation in the EmbeddableEntity class.

   import javax.persistence.EmbeddedId;
   import javax.persistence.Entity;

   @Entity
   public class EmbeddedEntity {

      @Id
      private int id;

      @Embedded
      private EmbeddableEntity ee;
   }
   import javax.persistence.Entity;

   @Entity
   public class EmbeddableEntity {

      private int embedField;

      ...
   }

To resolve the issue, manually inspect the use of the EmbeddableEntity class to verify that it is not also used as an entity class so that you can change the @Entity annotation to @Embeddable.

   import javax.persistence.Embeddable;
   import javax.persistence.Id;

   @Entity
   public class EmbeddedEntity {

      @Id
      private int id;

      @Embedded
      private EmbeddableEntity ee;
   }
   import javax.persistence.Embeddable;

   @Embeddable
   public class EmbeddableEntity {

      private int field;

      ...
   }

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