【问题标题】:In hibernate4, Annotation @MapKey's targetElement property was replace by what?在 hibernate4 中,Annotation @MapKey 的 targetElement 属性被什么替换了?
【发布时间】:2013-06-02 02:20:47
【问题描述】:

在hibernate4中,注解@MapKey的targetElement属性被什么替换了?

@ElementCollection
@MapKey(targetElement = ProductAttribute.class)
@LazyCollection(LazyCollectionOption.TRUE)
@Cascade(value = { CascadeType.DELETE })
public Map<ProductAttribute, String> getProductAttributeMapStore() {
    return productAttributeMapStore;
}

现在,我把我项目的hibernate.jar从hibernate3升级到hibernate4.1,intellJ alert targetElement可以找到了。

【问题讨论】:

    标签: hibernate


    【解决方案1】:

    作为documentedorg.hibernate.annotations.Mapkey 注释已被弃用,取而代之的是javax.persistence.MapKeyColumn

    根据 API 文档,不推荐使用属性 targetElement,因为:

    仅当集合不使用泛型时才有用

    在这种特定情况下,使用 targetElement 是重复的,因为映射键的类型已经通过使用泛型给出:

    Map<ProductAttribute, String>
    

    【讨论】:

    • 为了使代码正确编译,将旧版MapKey替换为javax.persistence.MapKeyColumn是否正确?
    • 另一个问题:在hibernate4中,注解@MapKey被什么替换了?
    • 请看一下我非常相似的问题:stackoverflow.com/questions/32307329/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 1970-01-01
    • 2015-09-05
    • 2016-09-26
    相关资源
    最近更新 更多