使用 JPA 注释通过 hibernate 映射地图的困难
关于 JPA @MapKey 元素的语义,我可能不理解一些基本的东西。 我正在尝试保存具有实体键和实体值的映射。架构是自动的 由休眠生成。它生成一个连接表,将值实体映射到 包含实体(具有 Map 属性)并忽略键。 如此有效,它只是将其视为值的集合并忽略键, 据我所知。 我在这里缺少什么? 谢谢
@Entity
public class PracticeMap {
@javax.persistence.OneToMany(cascade = CascadeType.ALL)
@javax.persistence.MapKey
public Map<KeySample, ValueSample> getMap1() {
return map1;
}
//more unrelated/standard bits here
}
There is possibly something fundamental I don't understand about the semantics of JPA @MapKey element.
I am trying to save a Map that has entity keys and entity values. The Schema is auto
generated by hibernate. It generates a join table that maps the values entities to
the containing entity (that has the Map property) and ignores the keys.
so effectively it just treats it as a collection of values and ignores the keys,
as far as I can tell.
what am i missing here ?
Thank you
@Entity
public class PracticeMap {
@javax.persistence.OneToMany(cascade = CascadeType.ALL)
@javax.persistence.MapKey
public Map<KeySample, ValueSample> getMap1() {
return map1;
}
//more unrelated/standard bits here
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看
@MapKey
<的javadoc /a> - 当您需要将值实体的特定字段视为键时使用。如果您的键和值应该是不同的实体,则需要使用 < code>@MapKeyJoinColumn(在 JPA 2.0 中引入)。
Look at the javadoc of
@MapKey
- it's used when you need to treat particular fields of the value entity as keys.If your key and value should be different entities, you need to use
@MapKeyJoinColumn
(introduced in JPA 2.0).