gpt4 book ai didi

eclipse - @EmbeddedId : is not mapped as an embeddable

转载 作者:行者123 更新时间:2023-12-04 23:21:15 25 4
gpt4 key购买 nike

我收到了一个 Eclipse 错误:@EmbeddedId .

这是实体:

@Entity
@Table(name = "PERSON")
public class Person implements Serializable {

@EmbeddedId
private PersonPK PersonPK;

@Column(name = "AGE")
private int age;
}

和可嵌入类:
@Embeddable
public class PersonPK implements Serializable {

@Column(name = "FIRSTNAME")
private String firstName;

@Column(name = "LASTNAME")
private String lastName;

public PersonPK() {
}
}

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>

关于eclipse - @EmbeddedId : is not mapped as an embeddable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26163002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com