【发布时间】:2012-10-24 13:41:27
【问题描述】:
我正在尝试使以下类型的映射工作
Table event has the following columns:
id (PK)
prodgroup
errandtype
table errandtype : errandtype
table prodgroup: prodgroup
我有相应的 JPA 类
@Entity
@Table(name="event")
public class MyEvent {
@Id
int id;
// what mapping should go here?
Prodgroup prodgroup;
// what mapping should go here?
ErrandType errandtype;
}
@Entity
public class Prodgroup {
@Id
private String prodgroup;
}
@Entity
public class ErrandType {
@Id
private String errandtype;
}
好的,所以问题在代码中被标记为 cmets,但无论如何我会尽量明确。
在上面的示例中,我希望将 MyEvent 类中的 Prodgroup 和 ErrandType 字段设置为相应的 Prodgroup 和 Errandtype 实例
我已经尝试过 @OneToOne 与 @joincolumns 和 mappedby 属性的关系,但我就是无法让它工作,而且我已经失去了所有逻辑方法的感觉。我对 JPA 实体映射的掌握显然很薄弱。
那么任何人都可以澄清一下吗?
【问题讨论】:
-
您是否从 JPA 类中生成表?或者您正在尝试映射到现有表?
-
@user1697575 我正在尝试映射到现有表