简体   繁体   中英

JPA Hibernate and having ElementCollection for Map

Can we have an ElementCollection annotation on a field with collection within a collection?

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

I am getting MappingException at the moment with this so not sure if there are additional annotations or code involved or if I have to make a new class and perhaps use Embeddable and Embedded

You can use UserType or Atribute Converter with JPA attached to your collection I believe. I have never tested it on collection but I believe it is worth the shot:

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

When it comes to Hibernate you can try something like this UserCollectionType:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM