-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: inverse=true
PostPosted: Tue Aug 30, 2005 4:00 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Trying (and having trouble understanding) to understand "inverse" ...

ou may map a bidirectional one-to-many association by mapping a one-to-many association to the same table column(s) as a many-to-one association and declaring the many-valued end inverse="true".

...
...
...

<many-to-one name="Parent" column="parent_id" not-null="true"

(We also need to add the Parent property to the Child class.)

Now that the Child entity is managing the state of the link, we tell the collection not to update the link. We use the inverse attribute.

<set name="Children" inverse="true">
<key column="parent_id" />
<one-to-many class="Child" />
</set>


What's meant by "managing the state of the link"???

Reference:
http://nhibernate.sourceforge.net/nh-do ... ollections


Top
 Profile  
 
 Post subject: Re: inverse=true
PostPosted: Tue Aug 30, 2005 5:55 am 
Senior
Senior

Joined: Sat May 14, 2005 8:40 am
Posts: 130
nfung wrote:
What's meant by "managing the state of the link"???


That means that the Child is responsible for maintaining the relation between Parent and Child. Example:

Code:
// NHibernate looks at the Parent property for the relation
childObject.Parent = parentObject;


When you set inverse="false", the relation between Parent and Child is managed by the parent:

Code:
// NHibernate doesn't look at the Parent property of the Child, but looks in the Children collection of the Parent to establish the relation.
parentObject.Children.Add(childObject) ;

_________________
Cuyahoga


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 30, 2005 10:09 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
And it affects the order of the SQL commands executed...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: Help!
PostPosted: Wed Aug 31, 2005 5:03 am 
Regular
Regular

Joined: Mon May 30, 2005 11:20 pm
Posts: 66
Thanks first of all.... I have specified "inverse" = true in the parent object "zInventory":

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="warehouse.to.zInventory, WarehouseLib" table="zInventory">
   
      <id name="Inv_ID" column="inv_id" type="Int32" unsaved-value="0" >
         <generator class="identity" />
      </id>
      
      ... bunch of properties...
      
      <set name="Swatches" inverse="true" cascade="all" table="inv_swatches" lazy="false">
         <key column="inv_id"/>
         <one-to-many class="warehouse.to.inv_swatches, WarehouseLib"/>
      </set>
      
      
   </class>
</hibernate-mapping>



For my child object "Swatch":
Code:
Public Class inv_swatches
...
             Public Property ParentInventoryMaster() As warehouse.to.zInventory
      ... getter and setter...
      End Property
...
End Class


However, in my parent class, I have:
Code:
Public Class zInventory
...
Public Property Swatches() As Collections.ISet
         ... getters and setters...
      End Property
...
End Class


Is this wrong then? What I did is:
(1). Get children from parent class
AND
(2). Get parent from child class

I have this feeling from what you said you can ONLY do...
(1) if you specified inverse=false
OR
(2) if you specified inverse=true

For your information, my child class mapping file:

Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="warehouse.to.inv_swatches, WarehouseLib" table="inv_swatches">

      <id name="SwatchID" column="swatch_id" type="Int32" unsaved-value="0" >
         <generator class="identity" />
      </id>
      
      <many-to-one name="ParentInventoryMaster" column="inv_id" class="warehouse.to.zInventory, WarehouseLib" not-null="true" />
      
      ... other stuff ...
      
   </class>
</hibernate-mapping>


Is this the reason why I keep getting "Row not found" on updates/deletes (as noted in my other post... http://nhibernate.sourceforge.net/forum ... .php?t=644 )

Help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.