我得到了一个Eclipse错误:@EmbeddedId.
这是实体:
@Entity
@Table(name = "PERSON")
public class Person implements Serializable {
@EmbeddedId
private PersonPK PersonPK;
@Column(name = "AGE")
private int age;
}
Run Code Online (Sandbox Code Playgroud)
和嵌入类:
@Embeddable
public class PersonPK implements Serializable {
@Column(name = "FIRSTNAME")
private String firstName;
@Column(name = "LASTNAME")
private String lastName;
public PersonPK() {
}
}
Run Code Online (Sandbox Code Playgroud)
Eclipse向我显示了这个错误: PersonPK is not mapped as an embeddable
你能告诉我为什么以及如何解决这个问题?
老问题,我知道,但今天早上已经 - 并解决了 - 这个问题,这是另一种可能性:
在你的persistence.xml文件,如果exclude-unlisted-classes设置为true,那么你需要有@Embeddable列为持久单元托管类类.所以在上面的例子中,你会做这样的事情:
<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>
Run Code Online (Sandbox Code Playgroud)