6

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 ?

BnJ
  • 1,024
  • 6
  • 18
  • 37

5 Answers5

9

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>
dcsohl
  • 7,186
  • 1
  • 26
  • 44
  • was exactly my problem.... thx! I´m wondering why my application worked on glassfish... – cljk Jul 28 '17 at 09:46
1

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

Community
  • 1
  • 1
AngryMonkey
  • 144
  • 1
  • 1
  • 7
0

It's possible PersonPK is listed as an Entity in an orm.xml file. The settings in an orm.xml file override the Java annotations. Remove PersonPK from the orm.xml file (or list it as an Embeddable there also) and the error will go away.

Brian Vosburgh
  • 3,146
  • 1
  • 18
  • 18
  • I don't have PersonPK listed in my orm.xml. How to list it as Embeddable ? – BnJ Oct 03 '14 at 07:40
  • If you do not already have an `orm.xml` file, you probably do not need to create one. But, if you do not have an `orm.xml` file, I do not know what could be causing that particular error. What version of Eclipse are you using? Does it have any third party extensions added to it? – Brian Vosburgh Oct 03 '14 at 15:43
0

Try the following in your orm.xml

<entity-mappings> 
<entity class="package.Person"> 
<attributes> 
... 
<embedded-id name="personPK"/> 
... 
</attributes> 
</entity> 
<embeddable class="package.PersonPK"/> 
</entity-mappings>
Gas
  • 17,601
  • 4
  • 46
  • 93
0

I had the same error.

In my case I had an @Entity annotation on PersonPK (the Embeddable class).

Don't combine @Entity and @Embeddable on the same class :)

I removed @Entity from PersonPK and all is now good with the world.

Brett Sutton
  • 3,900
  • 2
  • 28
  • 53