Note that there are some explanatory texts on larger screens.

plurals
  1. POstruts 1 throws org.hibernate.TransientObjectException
    primarykey
    data
    text
    <p>I am trying to add activity auditing to my struts 1 application. I change an object and then I want to create a row in my auditing table that refers to the changed object. I am getting TransientObjectException because I've changed the referent object. I tried flushing the session, but that didn't solve it and I'm not sure why.</p> <pre><code>merchant.setTrusted(false); merchantDAO.saveOrUpdate(merchant); // trying to resolve org.hibernate.PropertyValueException: not-null property references a null or transient value: com.rc.model.ActivityAudit.user SessionManagerFactory.getSessionManager(DatasourceType.M).getSession().flush(); ActivityAuditManager.addActivityAudit("Set merchant to untrusted", merchant, userAccount); </code></pre> <p>where ActivityAuditManager.addActivityAudit() is:</p> <pre><code>public static void addActivityAudit(String action, Merchant merchant, IMerchantUserAccount user) { ActivityAudit activityAudit = new ActivityAudit(merchant, action, user, new Date()); activityAuditDAO.saveOrUpdate(activityAudit); } </code></pre> <p>The exception I'm getting is:</p> <pre><code>org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing </code></pre> <p>but as far as I can tell I <em>am</em>.</p> <p>ETA mapping:</p> <pre><code>&lt;class name="com.rc.model.ActivityAudit" table="activity_audit" discriminator-value="0"&gt; ... &lt;many-to-one name="merchant" class="com.rc.model.Merchant" column="merchantid" unique="false" not-null="true" cascade="none"/&gt; ... </code></pre> <p>I tried <code>cascade="all"</code> and <code>cascade="save-update"</code> and neither improves the situation.</p> <p>ETA: See my own answer, below, but <code>cascade="save-update"</code> actually did fix it.</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.
    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