Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@EmbeddedId : is not mapped as an embeddable

Tags:

eclipse

jpa

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 ?

like image 813
BnJ Avatar asked Oct 02 '14 14:10

BnJ


People also ask

What is embeddable in JPA?

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.

What is embeddable entity?

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.

What is the use of embeddable annotation?

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.

What is embeddable in Hibernate?

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.


2 Answers

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>
like image 86
dcsohl Avatar answered Oct 01 '22 22:10

dcsohl


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

like image 41
AngryMonkey Avatar answered Oct 01 '22 22:10

AngryMonkey