Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The mapping you've posted and the description you provided conflict with each other:</p> <ol> <li>Mapping join column on inverse association as non-insertable/updatable is not going to work. How is that column going to be updated (and your parent-child association maintained)?</li> <li>Your child mapping defines Child's PK as childId (using @Id annotation). That's NOT how a composite key is mapped; Hibernate will consider childId to be a simple primary key.</li> <li>Your criteria doesn't match your mapping (ParentTable vs Parent, etc...) which is probably a conversion artifact, but other then that looks OK.</li> </ol> <p>I'd use aliases, though:</p> <pre><code>Criteria criteria = session.createCriteria(Parent.class) .add(Restrictions.eq("policyNo", "1234")) .createAlias("child", "children") .add(Restrictions.ne("children.transType", "VIEW")); </code></pre> <p><strong>Update</strong> (based on criteria / generated SQL):</p> <p>Take a look at the SQL generated by Hibernate based on your criteria (shortened for readability):</p> <pre><code>SELECT this_.*, ts1_.*, copolicypo4_.* FROM CoPolicyPointer this_ INNER JOIN CoTransactionSummary ts1_ ON this_.systemAssignId=ts1_.systemAssignId LEFT JOIN CoPolicyPointer copolicypo4_ ON ts1_.systemAssignId=copolicypo4_.systemAssignId </code></pre> <p>You'll notice that your "parent" table (<code>CoPolicyPointer</code>) is joined <strong>twice</strong> even though your criteria only joins the "children" table. That happens because you're specifying entity names in <code>@Entity</code> annotations but creating your criteria using <strong>original</strong> class name, making Hibernate think you're joining three separate entities:</p> <ol> <li>Criteria is based on <code>CoPolicyPointerRedo.class</code></li> <li>It joins to <code>CoTransactionSummaryRedo.class</code> whose entity name is <code>CoTransactionSummary</code> </li> <li>Which joins back to <code>CoPolicyPointerRedo.class</code> as ``CoPolicyPointer<code>using</code>@ManyToOne`</li> </ol> <p>You need to be consistent with naming. Either remove <code>name</code> from <code>@Entity</code> declarations (you can use <code>@Table</code> instead to specify table name) or create your criteria using <a href="http://docs.jboss.org/hibernate/stable/core/api/org/hibernate/Session.html#createCriteria(java.lang.String)" rel="nofollow noreferrer"><code>session.createCriteria(String entityName)</code></a> method which takes entity name rather than class name as parameter.</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