gx0r
gx0r

Reputation: 5471

How do I persist a Map<String, Map<String, String>> with JPA?

Map<String, Map<String, String>> someMap = new HashMap<>();

How can one persist this with JPA 2.1?

Upvotes: 2

Views: 1129

Answers (1)

Zielu
Zielu

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

Related Questions