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.
EmbeddedId annotation references an embeddable class that has an Id
annotation, the rule flags the Id annotation as a severe issue. The Id annotation
will need to be removed.
EmbeddedId annotation, the rule
flags the issue as a warning. You can expand the scope of the analysis to include any attributes annotated with
EmbeddedId that might reference the embeddable class and rerun the scan, or you can manually verify
that no EmbeddedId annotations reference the embeddable class.
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.