I am struggling for almost a week of how to store a HashMap using JPA in Play. All the other attributes are stored, only the HashMap has zero elements (is empty).
public class ImageModel extends Model {
@Id
private String id;
private String url;
@ElementCollection(targetClass = java.lang.String.class)
@MapKeyClass(java.lang.String.class)
private Map<String,String> tags = new HashMap<>();
// the method for adding keys and values to the HashMap
public void add(String key, String value){
tags.put(key,value);
this.save();
}
}
I also tried to annotate with:
@ElementCollection(fetch=FetchType.LAZY)
So, my only guess for now is that I have not configured well Play. (I must say that I am using Play2 and haven't configured anything, except deleting "#" (comment mark) in front of database settings).
On Play documentation says: "There is no built-in JPA implementation in Play 2.0". Could be that the case?
Update: I have made some research and said that could be because I'm using the default database from Play - H2. I tried with MySQL - video how to do it , but again it saves only the id and url. I looked in MySQL database and table with the name of the class had only 2 attribute (id and url), no trace of my HashMap.
Update2: Added a print screen - with database query.
Update3: The sample "computer-database-jpa" from Play is working fine, so the JPA should be fine, but that sample didn't used a Map (HashMap). I even changed hibernate with EclipseLink, but still not working. :( (although, all the basic types attributes are in database)