Note that there are some explanatory texts on larger screens.

plurals
  1. POPlay Framework: Solution for storing a Map, key - value using JPA
    primarykey
    data
    text
    <p>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).</p> <pre><code>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&lt;String,String&gt; tags = new HashMap&lt;&gt;(); // the method for adding keys and values to the HashMap public void add(String key, String value){ tags.put(key,value); this.save(); } } </code></pre> <p>I also tried to annotate with:</p> <pre><code>@ElementCollection(fetch=FetchType.LAZY) </code></pre> <p>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).</p> <p>On Play documentation says: "<strong>There is no built-in JPA implementation in Play 2.0</strong>". Could be that the case?</p> <p><strong>Update</strong>: I have made some research and said that could be because I'm using the default database from Play - H2. I tried with MySQL - <a href="http://www.youtube.com/watch?v=HwDlnTg_H-o" rel="nofollow">video how to do it</a> , 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.</p> <p><strong>Update2</strong>: Added a print screen - <a href="http://prntscr.com/17b2t9" rel="nofollow">with database query.</a></p> <p><strong>Update3</strong>: 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)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload