Reputation: 5471
Map<String, Map<String, String>> someMap = new HashMap<>();
How can one persist this with JPA 2.1?
Upvotes: 2
Views: 1129
Reputation: 8552
You could serialize it and store it as blob in one column:
@Lob
HashMap<String, Map<String, String>> someMap = new HashMap<>();
//!!!!it needs to be declared as HashMap not Map as Serializable is required for this field
But it works only if you dont want to run queries against content of the map, as in the DB it is stored of course as a sequence of bytes that DB does not understand.
You cannot have @ElementCollection of @ElementCollection in JPA and that is what you would need to have 2 level of maps.
Upvotes: 3