-->
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.  [ 8 posts ] 
Author Message
 Post subject: Versioning and custom update statements
PostPosted: Thu Jan 04, 2007 2:38 am 
Newbie

Joined: Wed Dec 20, 2006 10:03 pm
Posts: 2
NHibernate 1.2.0.Beta2

Am I correct in stating that Versioning won't work when you use custom SQL for the update statements on an object?

For example in the class mapping file

<sql-update>exec up_UpdateData ?, ?, ?, ?</sql-update>

is used to so when we call

session.Update(myTestObject);

no StaleObjectStateException is thrown even though it's passing to the stored procedure the new and old version number associated with myTestObject.

It works when we don't override the Update and I was hoping for it to work in the same manner when we did.

Thanks
Rhys


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 12:34 am 
Newbie

Joined: Mon Nov 20, 2006 1:53 am
Posts: 14
I am having exactly the same problem here.


This is the mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

<class name="Server.Test03, Server" table="Table02" lazy="false">
<cache usage="read-write"/>
<id name="Key" column="myKey" unsaved-value="null">
<generator class="assigned" />
</id>
<version name="Version" column="version" type="Int32" unsaved-value="0" />
<property name="MyValue" column="myName" type="String" length="50"/>
</class>

</hibernate-mapping>

When i try to force (for testing purposes) a StaleObjectException this works fine. But as soon as I change the mapping file to use a stored procedure for updates like this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

<class name="Server.Test03, Server" table="Table02" lazy="false">
<cache usage="read-write"/>
<id name="Key" column="myKey" unsaved-value="null">
<generator class="assigned" />
</id>
<version name="Version" column="version" type="Int32" unsaved-value="0" />
<property name="MyValue" column="myName" type="String" length="50"/>
<sql-update>exec up_UpdateData3 ?, ?, ?, ?</sql-update>
</class>

</hibernate-mapping>

The data just gets updated and no stale exception is thrown when it should be. Why would this be the case does anyone know??

Clare


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 12:34 am 
Newbie

Joined: Mon Nov 20, 2006 1:53 am
Posts: 14
I am having exactly the same problem here.


This is the mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

<class name="Server.Test03, Server" table="Table02" lazy="false">
<cache usage="read-write"/>
<id name="Key" column="myKey" unsaved-value="null">
<generator class="assigned" />
</id>
<version name="Version" column="version" type="Int32" unsaved-value="0" />
<property name="MyValue" column="myName" type="String" length="50"/>
</class>

</hibernate-mapping>

When i try to force (for testing purposes) a StaleObjectException this works fine. But as soon as I change the mapping file to use a stored procedure for updates like this:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

<class name="Server.Test03, Server" table="Table02" lazy="false">
<cache usage="read-write"/>
<id name="Key" column="myKey" unsaved-value="null">
<generator class="assigned" />
</id>
<version name="Version" column="version" type="Int32" unsaved-value="0" />
<property name="MyValue" column="myName" type="String" length="50"/>
<sql-update>exec up_UpdateData3 ?, ?, ?, ?</sql-update>
</class>

</hibernate-mapping>

The data just gets updated and no stale exception is thrown when it should be. Why would this be the case does anyone know??

Clare


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 7:04 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Does your stored procedure return 1 affected row in case it succeeded and 0 affected rows in case it failed? This is what NHibernate expects in this case.

Also, you can try detecting stale state in your stored procedure and signal an error manually.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 6:08 pm 
Newbie

Joined: Mon Nov 20, 2006 1:53 am
Posts: 14
I traced the database called and it definately returnes

(1 row(s) affected)

Clare Stinton


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 6:20 pm 
Newbie

Joined: Mon Nov 20, 2006 1:53 am
Posts: 14
In fact it returns this each time it is called (it successfully runs) even when trying to update a stale object.

Clare


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 11, 2007 7:51 pm 
Senior
Senior

Joined: Sat Mar 25, 2006 9:16 am
Posts: 150
The stored proc should return 0 affected rows if the object is stale


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Thu Jan 11, 2007 8:06 pm 
Newbie

Joined: Wed Dec 20, 2006 10:03 pm
Posts: 2
Yes thanks for that, I had to change the stored procedure to take account of the version in the update.


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