Embeddable classes cannot have an Id annotation when referenced by an EmbeddedId annotation

According to the Java Persistence API (JPA) specification, if an entity defines an attribute with an EmbeddedId annotation, the embeddable class cannot contain an attribute with an Id annotation. If both the EmbeddedId annotation and the Id annotation are defined, OpenJPA ignores the Id annotation, whereas EclipseLink throws an exception.

This rule detects Embeddable classes that contain attributes with an Id annotation, then the rule flags the Id annotations depending on whether it finds an entity that references the embeddable class using an EmbeddedId annotation.

In this example, the rule flags the Id annotation in the EmbeddableObject class.

   import javax.persistence.EmbeddedId;
   import javax.persistence.Entity;
   
   @Entity
   public class MainEntity {

      @EmbeddedId
      private EmbeddableObject eo;
   }
   import javax.persistence.Embeddable;
   import javax.persistence.Id;
   
   @Embeddable
   public class EmbeddableObject {

      @Id
      private int field;

      ...
   }

To resolve the issue, remove the @Id annotation and its import.

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

   @Entity
   public class MainEntity {

      @EmbeddedId
      private EmbeddableObject eo;
   }
   import javax.persistence.Embeddable;
   
   @Embeddable
   public class EmbeddableObject {

      private int field;

      ...
   }

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