我的代码有问题(显然),经过互联网上的多次搜索后,我找不到问题的答案,所以我在这里问我的问题.我有这个 :
@Entity
public class Resident
{
/** Attributes */
@EmbeddedId
private IdResident idResident;
...
@Embeddable
public class IdResident {
@Column(name="NOM")
private String nom;
@ManyToOne
@JoinColumn(name="CODE")
private Port port;
...
@Entity
public class Port
{
/** Attributes */
@Id
@Column(name="CODE")
private String code;
@Column(name="NOM")
private String nom;
...
Run Code Online (Sandbox Code Playgroud)
我正在使用Maven,我在persistence.xml中写了这个:
<class>beans.Port</class>
<class>beans.Resident</class>
Run Code Online (Sandbox Code Playgroud)
但是当我运行程序时,无论我写什么,我都有:
Exception Description: The mapping [port] from the embedded ID class
[class beans.IdResident] is an invalid mapping for this class. An embeddable class that
is used with an embedded ID specification (attribute [idResident] from the source
[class beans.Resident]) can only contain basic mappings. Either remove the non
basic mapping or change the embedded ID specification on the source to be embedded.
Run Code Online (Sandbox Code Playgroud)
我不知道我的错误在哪里,我认为这是因为IdResident类中有一个Entity对象,但我不知道如何将它弄错
您得到的错误消息很好地解释了它,用作嵌入式ID的Embeddable只能包含基本映射,而不能包含关系.在JPA 2.0规范中,这用以下词语告知:
不支持在嵌入式id类中定义的关系映射.
只需定义属于embeddable中复合id的一部分的属性,用作嵌入式id,以及实体本身中的映射关系(或另一个可嵌入和包含@Embedded的映射).
| 归档时间: |
|
| 查看次数: |
10418 次 |
| 最近记录: |