Note that there are some explanatory texts on larger screens.

plurals
  1. PO@ElementCollection not saved by Hibernate 4.0.1
    text
    copied!<p>I have class (entity) <code>A</code> which contains list of objects (entities) <code>B</code> which contains <code>Set&lt;String&gt; strings</code>.</p> <pre><code>@Entity @Table(name = "a") public class A { private int id; private List&lt;B&gt; bList; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "aId") public int getId() { return id; } @OneToMany(fetch = FetchType.EAGER) @JoinColumn(name = "aId", nullable = false) @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE}) public List&lt;B&gt; getBList() { return bList; } ... setters and other stuff } </code></pre> <hr> <pre><code>@Entity @Table(name = "b") public class B { private int id; private int aId; private Set&lt;String&gt; strings; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "bId") public int getId() { return id; } @ElementCollection(fetch = FetchType.EAGER) @CollectionTable(name = "b_strings", joinColumns = {@JoinColumn(name = "bId")}) @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})** public Set&lt;String&gt; getStrings() { return strings; } @Column(name = "aId", insertable = false, updatable = false) public int getAId() { return aId; } ... setters and other stuff } </code></pre> <p>I create object <code>A</code> and then I try to save it:</p> <pre><code>A a = new A(); List&lt;B&gt; l = new ArrayList&lt;B&gt;(); a.setBList(l); B b = new B(); l.add(b); b.setStrings(new HashSet&lt;String&gt;()); b.getStrings().add("1"); b.getStrings().add("2"); b = new B(); l.add(b); b.setStrings(new HashSet&lt;String&gt;()); b.getStrings().add("3"); Session session = sessionFactory.openSession(); session.saveOrUpdate(a); session.close(); </code></pre> <p><code>A</code> and <code>B</code> object is saved (inserted) but set with <code>strings</code> is not saved. I'm using Spring 3.1 and Hibernate 4.0.1. Why is hibernate ignoring <code>@ElementCollection</code>? Table is created, mysql workbech shows it as readonly...</p>
 

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