-->
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.  [ 1 post ] 
Author Message
 Post subject: PostUpdateEvent - Getting foreign key values
PostPosted: Wed Nov 09, 2011 5:16 pm 
Newbie

Joined: Tue Aug 17, 2010 7:54 pm
Posts: 1
I've got a PostUpdateEvent logging all dirty fields. I use the PostUpdateEvent.Persister.ClassMetaData (from the persister) to weed out collections.

However, when I get to a many-to-one relationship, I need to log the value referenced in the foreign key, not the object itself.

So I could have the following mapping:


Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="false" assembly="McDo.Core" default-lazy="true">
   <class name="WorkerInfo, McDo.Core" table="WorkerInfo">
      <id name="Id" column="WIN_ID" type="Int64">
         <generator class="native" />
      </id>
      <version name="Version" column="WIN_Version" />
      <property name="WeeklyHours" column="WIN_WeeklyHours" />
      <many-to-one name="WorkSchedule" column="WIN_WRS_ID" not-null="false" cascade="none" />
  </class>
</hibernate-mapping>


Let's say I have a worker that has workschedule with an ID of 5. I then go in and select a different workschedule (ID = 10) for him.


If I try to get the value like this:

Code:
var oldVal = postUpdateEvent.OldState[i].ToString();
var newVal = postUpdateEvent.State[i].ToString();


it'll return "McDo.Core.WorkSchedule", instead of "10".

Now, I know I can check for EntityTypes doing this:

Code:
var cmd = postUpdateEvent.Persister.ClassMetadata;
var isEntity = cmd.PropertyTypes[i].IsEntityType;


but once I've discovered it's an entity, how would I go about getting the value of the id in the foreign key?


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

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.