I got an Eclipse error with : @EmbeddedId
.
This is the entity :
@Entity
@Table(name = "PERSON")
public class Person implements Serializable {
@EmbeddedId
private PersonPK PersonPK;
@Column(name = "AGE")
private int age;
}
And the embeddable class :
@Embeddable
public class PersonPK implements Serializable {
@Column(name = "FIRSTNAME")
private String firstName;
@Column(name = "LASTNAME")
private String lastName;
public PersonPK() {
}
}
Eclipse show me this error : PersonPK is not mapped as an embeddable
Can you tell me why and how to fix that ?
In JPA a relationship where the target object's data is embedded in the source object's table is considered an embedded relationship, and the target object is considered an Embeddable object.
Embeddable classes are used to represent the state of an entity but don't have a persistent identity of their own, unlike entity classes. Instances of an embeddable class share the identity of the entity that owns it. Embeddable classes exist only as the state of another entity.
Annotation Type Embeddable. Defines a class whose instances are stored as an intrinsic part of an owning entity and share the identity of the entity. Each of the persistent properties or fields of the embedded object is mapped to the database table for the entity.
With Hibernate we can use the @Embeddable annotation to mark a class to be eligible as an embeddable class. We can use the @Embedded annotation to embed an embeddable class. The attributes of embedded class can be overridden using the @AttributeOverrides and the @AttributeOverride annotations.
Old question, I know, but having had--and solved--this very problem this morning, here's another possibility:
In your persistence.xml file, if exclude-unlisted-classes
is set to true
, then you need to have the @Embeddable
class listed as a managed class in the persistence unit. So in the above case, you would do something like this:
<persistence-unit name="default" transaction-type="JTA">
<!-- ..... -->
<class>com.example.foobar.Person</class>
<class>com.example.foobar.PersonPK</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<!-- ..... -->
</persistence-unit>
You could also disable JPA validation for builds.
Right-click on the project and select properties. Select Validation and check Enable project specific settings. Uncheck JPA Validator. Clean the project.
Source: Problem with JPA Project in Eclipse - error in class annotated @Entity: Table "xxx" cannot be resolved
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With