-->
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.  [ 4 posts ] 
Author Message
 Post subject: Inheritance with NHibernate
PostPosted: Wed Dec 05, 2007 11:00 am 
Newbie

Joined: Wed Dec 05, 2007 10:24 am
Posts: 2
I need help with that.

I try to update a base object in db with his child object and appear this exception:

NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) .


Mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="IrmTerminal" table="IRM_TERMINALS"
dynamic-update="true">

<id name="Id" column="IDTERMINAL" unsaved-value="-1">
<generator class="native" />
</id>

<property name="Guid" column="GUID" length="50" not-null="true" />
<property name="Name" column="NAME" length="50" not-null="true" />
<property name="Alias" column="ALIAS" length="50" not-null="false" />
<property name="IsAdTerminal" column="ISADTERMINAL" not-null="false" />
<property name="Active" column="ACTIVE" not-null="false" />
<property name="InsertDate" column="INSERTDATE" not-null="false" />
<property name="LastWsCall" column="LASTWSCALL" not-null="false" />
...
...
<many-to-one name="RollbackCommand" column="IDROLLBACKCOMMAND"/>
<property name="DeviceType" column="DEVICE_TYPE" not-null="false" />
<one-to-one name="TerminalConfig" class="IrmTerminalConfig"/>

<one-to-one name="TerminalInfo" class="IrmTerminalInfo"/>
<one-to-one name="SelectedSnapShot" class="IrmSnapShot"/>
<!--Here I'm going to define first specifyc type of terminal(V-Pro)-->
<joined-subclass name="IrmTerminalVpro"
table="IRM_TERMINALS_VPRO">
<key column = "IdTerminal"/>
<property name="HostName" column="HostName"
length="128" not-null="true" />
<property name="PowerState" column="PowerState" not-null="true" />
<property name="ProvisioningMode" column="ProvisioningMode" not-null="true" />
<property name="ProvisioningState" column="ProvisioningState" not-null="true" />
<property name="AmtUser" column="AMTUser" length="64" not-null="true" />
<property name="AmtPassword" column="AMTPassword" length="64" not-null="true" />
<property name="Ip" column="IP" length="10" not-null="true" />
<property name="IpCustom" column="IPCustom" length="15" not-null="false" />
<property name="Port" column="Port" not-null="true" />
<property name="RedirectPort" column="RedirectPort" not-null="false" />
<property name="Inserted" column="Inserted" length="8" not-null="true" />
<property name="Modified" column="Modified" length="8" not-null="false" />

<bag name="Operations" table="IRM_VPRO_OPERATIONS">
<key column="IdTerminal" />
<one-to-many class="IrmVproOperation" />
</bag>
</joined-subclass>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 12:32 pm 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
Is your unsaved value correct?

Generally with Identity columns you'd have a zero for unsaved value (which is the default)

Can you verify that the class you're trying to save has a valid id?

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 12:59 pm 
Newbie

Joined: Wed Dec 05, 2007 10:24 am
Posts: 2
I`m doing a copy of base type object in child type.
unsaved-value is 0 now, and ploblem continues.
I try to save this copy:

if (oTerminal is IrmTerminalVpro)
{
//vPro terminal already exist
oTerminalVpro = (IrmTerminalVpro)oTerminal;
}
else
{
//To Create new vPro terminal object
oTerminalVpro = new IrmTerminalVpro(oTerminal);
}

...
...
...

using (ITransaction oTrans = oSession.Session.Transaction)
{
oTrans.Begin();
oSession.Session.Evict(oTerminal);
oSession.Session.SaveOrUpdate(oTerminalVpro);
oTrans.Commit();
}
oSession.Session.Flush();

When I try to save or update is where exception appear.
I don't know what is the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 3:01 pm 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
If the ID is zero, then NHibernate thinks it is an existing record, and tries to update.

The update will affect zero rows, and thus you'll get that error.

Either change the default value of the pk property to -1 or remove the unsaved-value attribute.

_________________
------------------------------
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.  [ 4 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.