0

I am using dropwizard which internally uses JPA annotatons and hibernate to map objects. One of the object has a map field which I have defined as

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

I keep seeing the following error

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

I have tried a number of things mentioned on SO

Added the @MapKey annotation Added annotations on getters changed Map to HashMap nothing seems to fix it.

user_mda
  • 18,148
  • 27
  • 82
  • 145
  • where do you want to persist this Map? into a column? into a (join) table? into a column serialised? And what is the "targetClass" trying to do ? you have generics defined on the field so targetClass is irrelevant – Neil Stockton Apr 02 '17 at 06:01
  • yes as a column of the table serialized – user_mda Apr 02 '17 at 11:05
  • in which case you could either try `@Lob`, or alternatively use an `@AttributeConverter` like on this link http://www.datanucleus.org/products/accessplatform_5_1/jpa/mapping.html#one_many_map_converter_simple_simple – Neil Stockton Apr 02 '17 at 12:12

1 Answers1

0

You can use @MapKeyColumn(name="column_name"). This link might be useful: https://en.wikibooks.org/wiki/Java_Persistence/Relationships#Map_Key_Columns_.28JPA_2.0.29

Sehej
  • 109
  • 4
  • same result after adding the @MapKeyColumn annotation – user_mda Apr 02 '17 at 11:31
  • Did you try below code with Map routes = new HashMap(); Also using @MapKeyColumn. Check this similar question : http://stackoverflow.com/questions/4324839/java-hibernate-mapping-exception-could-not-determine-type-for-java-util-map – Sehej Apr 03 '17 at 02:04
  • and this : http://stackoverflow.com/questions/287201/how-to-persist-a-property-of-type-liststring-in-jpa – Sehej Apr 03 '17 at 02:19