Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suspect you may be falling at the first hurdle:</p> <p>As has been previously stated, Hibernate will update the object that you call <code>update()</code> on and then cascade down to any subsequent objects that require updating, following the rules you specify in the <code>@Cascade</code> attribute.</p> <p>The problem is that your <code>User</code> class owns the relationship and adding a <code>User</code> object to the <code>VirtualDomain.userset</code> collection does not alter the <code>User</code> object in any way. Thus even with a cascade, Hibernate will not update the <code>User</code> object as it doesn't think that it has to.</p> <p>Instead, when you add an object to the <code>VirtualDomain.userset</code> collection, ensure that the <code>VirtualDomain</code> is added to the <code>User.virtualdomainset</code> collection as well.</p> <pre><code>// given a VirtualDomain object VirtualDomain domain = getSession().load( VirtualDomain.class, 1234 ); // and a User object User user = getSession().load( User.class, 5678 ); // add the User to the VirtualDomain domain.getUserset().add( user ); // but also add the VirtualDomain to the user user.getVirtualdomainset().add( domain ); // update the VirtualDomain and the Cascade settings will also update the User getSession().update( domain ); </code></pre> <p>In cases like this I find it useful to provide a helper method for adding objects to collections, rather than using direct access to the collections themselves. e.g.</p> <pre><code>public class VirtualDomain { Set userset; /* snip... */ public void addUser( User user ) { getUserset().add( user ); user.getVirtualdomainset().add( this ); } } </code></pre> <p>Although it's worth remembering the advice of the Hibernate fore-fathers:</p> <blockquote> <p>"In a real system, you may not have a many-to-many association. Our experience is that there is almost always other information that must be attached to each link... the best way... is via an intermediate <em>assocation class</em>." (Java Persistence With Hibernate, p. 297/298 , ISBN 1-932394-88-5)</p> </blockquote>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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