2017-04-02 182 views
0

我正在使用内部使用JPA annotatons和hibernate映射对象的dropwizard。其中一个对象都有我所定义的地图领域的无法使用JPA注释映射哈希映射

@Column 
    @ElementCollection(targetClass=String.class) 
    Map<String, String> routes; 

我一直看到下面的错误

org.hibernate.MappingException: Could not determine type for: java.util.Map, at table 

我已经尝试了一些关于SO

新增提到的事情@MapKey注释 添加注释获取者 更改映射到HashMap似乎没有解决它。

+0

你想在哪里坚持这个地图?成列?成一个(加入)表?成串行化列? “targetClass”试图做什么?你有在字段上定义的泛型,所以targetClass是无关紧要的 –

+0

是作为表序列化的一列 –

+0

在这种情况下,您可以尝试'@ Lob',或者使用'@ AttributeConverter'就像这个链接http:// www .datanucleus.org/products/accessplatform_5_1/jpa/mapping.html#one_many_map_converter_simple_simple –

回答

0

您可以使用@MapKeyColumn(name =“column_name”)。此链接可能有用:https://en.wikibooks.org/wiki/Java_Persistence/Relationships#Map_Key_Columns_.28JPA_2.0.29

+0

添加@MapKeyColumn注释后的结果相同 –

+0

您是否尝试使用Map 下面的代码routes = new HashMap ();还使用@MapKeyColumn。检查这个类似的问题:http://stackoverflow.com/questions/4324839/java-hibernate-mapping-exception-could-not-determine-type-for-java-util-map – Sehej

+0

和这个:http:// stackoverflow。 COM /问题/ 287201 /如何对坚持-A-财产的型liststring功能于JPA – Sehej