-->
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.  [ 2 posts ] 
Author Message
 Post subject: Criteria.List issuing an update
PostPosted: Sun Jan 13, 2008 3:21 am 
Newbie

Joined: Thu Jan 10, 2008 3:50 am
Posts: 4
Hi,

If I run a query on a table that has a field with a foriegn key (although it can be of value null), NHibernate tries to issue an UPDATE statement.

If I do a Load of the same record it works fine. However, the Criteria.List gives me an error with could not update.

I'm not modifying the results. I'm just using a search condition. If I take the record and assign a value to the foreign key, then it works. But surely this shouldn't be necessary. My mapping files doesn't reference any one-to-one relationships and my property in question is:

<property name="SalesPersonId"/>

Again, Load works. Criteria.List does not, with the same exact data.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 14, 2008 11:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
There is not enough information to do a complete troubleshoot for you. However, try making the SalesPersonId property in your C#/VB class a Nullable<int> (or "int?" in C#). When NHibernate retrieves the row from database, it gets a NULL. When the session is flushed, NHibernate sees a zero; therefore, it thinks that you have changed it, thus issues an update. The reason Load() does not cause the same problem is Load() creates a lazy proxy; and it does not actually hit the database until you access the object's properties. If the proxy has not been initialized, then NHibernate concludes that it has not been updated.

At any rate, all of the above are speculations. Please include more information if it does not solve your problem.

_________________
Karl Chu


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