【问题标题】:JPA Hibernate and having ElementCollection for MapJPA Hibernate 和 Map 的 ElementCollection
【发布时间】:2016-11-10 08:44:08
【问题描述】:

我们可以在集合中包含集合的字段上添加 ElementCollection 注释吗?

@ElementCollection
private Map<String, List<String>> mappedData = new HashMap<String, List<String>>();

我目前收到 MappingException,因此不确定是否涉及其他注释或代码,或者我是否必须创建一个新类并可能使用 Embeddable 和 Embedded

【问题讨论】:

标签: java hibernate jpa


【解决方案1】:

我相信您可以使用带有 JPA 的 UserType 或 Atribute Converter 附加到您的集合中。我从未在收藏中测试过它,但我相信它值得一试:

@ElementCollection
     // applies to each element in the collection
@Convert(YourCustomConverter.class) 
private Map<String, List<String>> mappedData = new HashMap<String, List<String>>();

当涉及到 Hibernate 时,您可以尝试这样的 UserCollectionType:

http://www.javalobby.org/java/forums/m91832311.html

【讨论】:

    猜你喜欢
    • 2015-06-16
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 2011-08-31
    • 1970-01-01
    • 2013-01-21
    • 2011-06-25
    • 1970-01-01
    相关资源
    最近更新 更多