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.
Embedded annotation references a class that has an Entity
annotation, the rule flags the Entity annotation in the referenced class.
The fix for this case depends on whether the application uses this class as an
entity or an embeddable.
@Entity annotation to an @Embeddable annotation.@Embedded annotation and remove the @Embedded annotation.
Embedded annotation is on an attribute where the embedded class is not found
within the scope of the scan and cannot be verified, the Embedded annotation is flagged.
You can expand the scope of the analysis to include additional classes and rerun the scan,
or you can manually verify that the embeddable class is correctly annotated.
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.