-->
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.  [ 7 posts ] 
Author Message
 Post subject: Update to child of many-to-one updates the parent
PostPosted: Thu Jul 03, 2008 11:55 am 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
I have 2 classes related to each other through a
uni-directional many-to-one relationship.

Parent Child
-------------------- -----------------

TradeInformation <-- TradeSchedule


When we update the TradeSchedule (child) object, it also updates the parent even though the TradeInformation (parent) hasn't been changed within the session.

We have other many-to-one mappings in our system and they do not exhibit the same behavior so I'm wondering this has something to do with the Schedule hierarchy or if we have missed something obvious...

Also from one session to the next, it would be great if you could mark
which classes are NONMUTABLE. This could really speed up performance because NHibernate could ignore the objects marked as such on a session-by-session basis.

Here are our mappings...

TradeInformation.hbm.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="MyDomain" namespace="MyDomain.Trade" auto-import="true" >
  <class name="TradeInformation" table="trade" lazy="false" dynamic-insert="true" dynamic-update="true">
    <id name="Id" column="trade_id" type="Int32">
      <generator class="native" />
    </id>

    <properties.../>
   
   <many-to-one name="CurrentShape" class="MyDomain.Shapes.Shape" column="Shape_Id" access="field.camelcase"/>    
    <bag name="Details" table="trade_detail" inverse="true" cascade="all"  fetch="select" lazy="false">
      <key column="trade_id" />
      <one-to-many class="TradeDetail" />
    </bag>
   
  </class> 
</hibernate-mapping>


TradeSchedule
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assemblyMyDomain" namespaceMyDomain.Scheduling" auto-import="true" >
 
  <subclass name="TradeSchedule" extends="Schedule" lazy="false" discriminator-value="T">
  <many-to-one name="Trade" class="MyDomain.Trade.TradeInformation" column="trade_Id" access="field.camelcase"/>
  </subclass> 

</hibernate-mapping>


Schedule
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="MyDomain" namespace="MyDomain.Scheduling" auto-import="true" >
  <class name="Schedule" table="Schedule" lazy="false" dynamic-insert="true" dynamic-update="true">
    <cache usage="read-write"/>

    <id name="Id" column="schedule_id" type="Int32">
      <generator class="native" />
    </id>

    <discriminator column="Schedule_Indicator" type="String" length="1"/>
    
    <properties/>   

    <many-to-one name="Parent" class="Schedule" column="Parent_Id" access="field.camelcase"/>
   <many-to-one name="CurrentShape" class="MyDomain.Shapes.Shape" column="shape_id" access="field.camelcase" not-null="false"/>
    
   <bag name="Children" inverse="true" lazy="false" cascade="all">
     <key column="Parent_Id"/>
     <one-to-many class="Schedule"/>
   </bag> 

   <bag name="Transactions" inverse="true" lazy="false" >
     <key column="schedule_id"/>
     <one-to-many class="ScheduleTransaction"/>
   </bag>

   <bag name="Internal_Details" inverse="true" lazy="false" cascade="all">
     <key column="schedule_id"/>
     <one-to-many class="ScheduleDetail"/>
   </bag>

  </class>
 
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 4:14 pm 
Newbie

Joined: Mon Jul 07, 2008 2:29 pm
Posts: 1
I'm having this problem too. Does anyone out there have any ideas?

- Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 2:15 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Where did you see that an update happened ? Just in hibernate's log or really in the database ? Maybe it's just a misleading log info ?

Dou you have version or timestamp columns in these classes ? Can you post the debug log ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 12:34 pm 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
wolli wrote:
Where did you see that an update happened ? Just in hibernate's log or really in the database ? Maybe it's just a misleading log info ?

Dou you have version or timestamp columns in these classes ? Can you post the debug log ?


Thanks for the reply. I didn't notice this in the logs at all.
We are using a custom Audit Interceptor to update the LastModifiedBy and LastModifiedByDate fields of the Trade when it is updated.

I will tho turn on the NHibernate logs and run our test and capture the log information for you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 1:23 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Does this also happen when you disable the audit interceptor ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 1:23 pm 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Double posting, sorry.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 08, 2008 3:29 pm 
Regular
Regular

Joined: Tue Feb 07, 2006 4:27 pm
Posts: 69
wolli wrote:
Where did you see that an update happened ? Just in hibernate's log or really in the database ? Maybe it's just a misleading log info ?

Dou you have version or timestamp columns in these classes ? Can you post the debug log ?


Hey! What a novel idea. Turning on the log!

I discovered what the issue was. One of the fields of the TradeInformation object is an enumerated type which I had mapped as Int32 instead of letting NHibernate reflect on the type for this field.

When NHibernate checked if this object was dirty it also checked the type and thought it dirty. I removed the type definition for this field and it is now working as expected.

Thanks for the tips and in the future I'll be turning on the logs a bit more!

Cheers

-Greg


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.