【发布时间】:2014-05-20 09:06:48
【问题描述】:
我正在尝试将一个简单的属性映射作为我的一个持久对象的键值对持久化。我在这件事上找到了一个很好的指南here。但它只显示了当键的值是映射对象(具有“映射者”属性)时如何映射。我的场景比这更简单。我只需要为一个键值对保留一个Map<String, String>。我发现我可以使用@ElementCollection,但它仅在 JPA 2 上受支持(我正在开发的平台仍在 JPA1 上)。
这是我的代码到目前为止的样子:
@Entity
public class MyClass {
private Map<String, String> attributes;
@OneToMany
@MapKey(name="key")
@JoinTable(name="MyClass_attributes")
public Map<String, String> getAttributes () {
return this.attributes;
}
public void setAttributes(Map<String, String> attributes) {
this.attributes = attributes;
}
}
但是我收到了这个错误:
Caused by: org.hibernate.AnnotationException:
Use of @OneToMany or @ManyToMany targeting
an unmapped class: mypackage.MyClass.attributes[java.lang.String]
【问题讨论】:
标签: java hibernate jpa orm jpa-1.0