Note that there are some explanatory texts on larger screens.

plurals
  1. POMap<String, String> with JPA
    primarykey
    data
    text
    <p>I have JPA entity like this:</p> <pre><code>@Entity @Table(name = "ATTRIBUTE") public class Attribute { //ID stuff @Column(name = "NAME", nullable = false) private String name; @Column(name = "VALUE", nullable = false) private String value; //getters and setters } </code></pre> <p>And the other entity:</p> <pre><code>@Entity @Table(name = "ATTRIBUTE_GROUP") public class AttributeGroup { //ID stuff @ElementCollection(fetch = FetchType.LAZY, targetClass = java.lang.String.class) @CollectionTable(name = "ATTRIBUTE") @MapKeyColumn(name = "NAME") @Column(name = "VALUE") private Map&lt;String, String&gt; attributes = new HashMap&lt;&gt;(); public void createAttribute(String name, String value) { Attribute attribute = new Attribute(); attribute.setName(name); attribute.setValue(value); attribute.setAttributeGroup(this); attributes.put(name, value); } public Map&lt;String, String&gt; getAttributes() { return attributes; } } </code></pre> <p>I need to have a map in <code>AttributeGroup</code> entity which will have <code>Attribute</code>'s name as a key and <code>Attribute</code>'s value as a value.</p> <p>The current approach does not work for me. When I am trying to persist records to the database it generates exception that transaction is marked as roolback only. I don't know if it is even the write way to do this, well if it is not working obviously it is not.</p> <p>How can I achieve this in JPA to have a map in <code>AttributeGroup</code> made from <code>Attribute</code> name/value paired object?</p> <p>I am using Hibernate via EntityManager.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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