-->
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.  [ 6 posts ] 
Author Message
 Post subject: Id field not updating on cascading update
PostPosted: Fri Jun 30, 2006 8:45 am 
Newbie

Joined: Fri Jun 30, 2006 8:37 am
Posts: 8
Hi,

I'm new to NHibernate and wonder if anyone could assist with a problem I'm experiencing.

I have an object consisting of 2 tables - notification and primaryaddressees. These tables are set in a one-to-many relationship(i.e. one notification, multiple primary addressees. When performing an addition using Session.SaveOrUpdate, all fields on both tables are updated except the Notification ID value within the primaryaddressee table.

Could anyone point me as to where they think the problem could lie?

Thanks in anticipation


Last edited by turtle1963 on Fri Jun 30, 2006 9:16 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 9:00 am 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
Can you post your mapping file?

If you are updating a PrimaryAddress object, then the db call will look like this:

UPDATE PrimaryAddresses
SET .....
WHERE PrimaryAddress_id=@some_id

and the foreign key to Notifications shouldn't be changed here, so it won't be in the update.

HTH.

_________________
------------------------------
Ben Scheirman
http://www.flux88.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 9:10 am 
Newbie

Joined: Fri Jun 30, 2006 8:37 am
Posts: 8
Here's the notification mapping file:-

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SCF.FMS.DataModel.Notification, DataModel" table="Notification">
<id name="Id" type="Int32" unsaved-value="0">
<column name="NotificationID" sql-type="int" not-null="true" unique="true" index="PK_Notification"/>
<generator class="native" />
</id>
<property name="NotificationSubject" type="String">
<column name="NotificationSubject" length="50" sql-type="varchar" not-null="false"/>
</property>
<property name="NotificationDate" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate">
<column name="NotificationDate" sql-type="datetime" not-null="false"/>
</property>
<property name="NotificationText" type="String">
<column name="NotificationText" length="50" sql-type="varchar" not-null="false"/>
</property>
<property name="NotificationStatus" type="String">
<column name="NotificationStatus" length="50" sql-type="varchar" not-null="false"/>
</property>
<bag name="NotificationReadMarks" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="NotificationID"/>
<one-to-many class="SCF.FMS.DataModel.NotificationReadMark, DataModel"/>
</bag>
<bag name="NotificationSecondaryAddressees" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="NotificationID"/>
<one-to-many class="SCF.FMS.DataModel.NotificationSecondaryAddressee, DataModel"/>
</bag>
<bag name="NotificationPrimaryAddressees" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="NotificationID"/>
<one-to-many class="SCF.FMS.DataModel.NotificationPrimaryAddressee, DataModel"/>
</bag>
<bag name="NotificationNotes" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="NotificationID"/>
<one-to-many class="SCF.FMS.DataModel.NotificationNote, DataModel"/>
</bag>
<bag name="Proposals" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="NotificationID"/>
<one-to-many class="SCF.FMS.DataModel.Proposal, DataModel"/>
</bag>
<bag name="Countries" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="NotificationID"/>
<one-to-many class="SCF.FMS.DataModel.Country, DataModel"/>
</bag>
</class>
</hibernate-mapping>

And here's the primary addresse mapping file:-

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SCF.FMS.DataModel.NotificationPrimaryAddressee, DataModel" table="NotificationPrimaryAddressee">
<id name="Id" type="Int32" unsaved-value="0">
<column name="NotificationPrimaryAddresseeID" sql-type="int" not-null="true" unique="true" index="PK_NotificationPrimaryAddressee"/>
<generator class="native" />
</id>
<property name="NotificationType" type="String">
<column name="NotificationType" length="50" sql-type="varchar" not-null="false"/>
</property>
<property name="NotificationEmailAddress" type="String">
<column name="NotificationEmailAddress" length="50" sql-type="varchar" not-null="false"/>
</property>
<many-to-one name="Notification" class="SCF.FMS.DataModel.Notification, DataModel">
<column name="NotificationID" sql-type="int" not-null="false"/>
</many-to-one>
<many-to-one name="User" class="SCF.FMS.DataModel.User, DataModel">
<column name="UserID" sql-type="int" not-null="false"/>
</many-to-one>
</class>
</hibernate-mapping>

The update I was performing was on the main notification that contained a child primaryaddressee. The update statement looks like this:-


NHibernate.ISession session = HSession.getSession(); //get handle to current session

session.SaveOrUpdate(objNotificationData);


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 9:42 am 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
at first glance, your mapping looks ok to me.

So a primary address may not have a NotificationId ?

_________________
------------------------------
Ben Scheirman
http://www.flux88.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 10:12 am 
Newbie

Joined: Fri Jun 30, 2006 8:37 am
Posts: 8
A primaryAddressee should really always have a NotificationID. I had only set the mapping file and database schema to allow a null value to prevent an error on the saveOrUpdate statement.

Are there any easy ways to code round this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 12:08 pm 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
You shouldn't get an error there. If the primary addresses are really aggregates (ie: they can't live outside of a notification), then you should map it accordingly.

Where were you getting the error? Maybe we should solve that problem first...

_________________
------------------------------
Ben Scheirman
http://www.flux88.com


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