Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernate saveOrUpdate() doesn't seem to cascade creation and saving
    primarykey
    data
    text
    <p>I'm new to Hibernate and am trying to save a "UserState" with a list of "WorkspaceState"s. UserState objects are keyed by a username that is set, the WorkspaceStates are set by UUID scheme. My issue is that if I have a UserState with one WorkspaceState in it, the UserState gets saved but the WorkspaceState does not.</p> <p>Here are the Hibernate mapping</p> <pre><code>&lt;hibernate-mapping&gt; &lt;class name="UserState" table="USERSTATE"&gt; &lt;id name="owner" type="java.lang.String"&gt; &lt;column name="OWNER" /&gt; &lt;generator class="assigned" /&gt; &lt;/id&gt; &lt;list name="workspaces" inverse="false" cascade="all" table="WORKSPACESTATE" lazy="true"&gt; &lt;key&gt; &lt;column name="UID" /&gt; &lt;/key&gt; &lt;list-index&gt;&lt;/list-index&gt; &lt;one-to-many class="WorkspaceState" /&gt; &lt;/list&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; &lt;hibernate-mapping&gt; &lt;class name="WorkspaceState" table="WORKSPACESTATE"&gt; &lt;id name="uid" type="java.lang.String"&gt; &lt;column name="UID" /&gt; &lt;generator class="uuid" /&gt; &lt;/id&gt; &lt;property name="owner" type="java.lang.String"&gt; &lt;column name="OWNER" /&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>I have a UserState object with one WorkspaceState in it. When I do a session.saveOrUpdate(userst), I see that hibernate has already removed the WorkspaceState from my userst object. Then the commit saves it to the DB without the workspacestate in it.</p> <p>In truth the WorkspaceState themselves have lists, but I suspect whatever I'm doing wrong continues onward.</p> <p>Thanks</p> <p>Edit - how it's committed. HibernateUtil is as it appears in the standard hibernate document examples:</p> <pre><code>Session session = HibernateUtil.getSessionFactory().openSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); String username = (String) session.merge(state); transaction.commit(); } catch (HibernateException e) { transaction.rollback(); e.printStackTrace(); return false; } finally { session.close(); } </code></pre>
    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.
 

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