-->
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: Issue with Version mapping and Generated Properties
PostPosted: Mon May 05, 2008 11:15 am 
Newbie

Joined: Tue Mar 06, 2007 5:28 pm
Posts: 6
I have an issue with a DELETE, with the <version> tag with a generated property.

I have a class with a generated version:

Code:
<class name="Foo" table="Foo" lazy="false">
<id name="FooId" column="FooId">
  <generator class="identity"></generator>
</id>
<version name="VersionInt" column="VersionInt" type="Int32" generated="always" />
<property name="FooName"/>
<bag name="FooBars" inverse="true" cascade="all">
  <key column="FooId"/>
  <one-to-many class="LnkFooBar"/>
</bag>
</class>


When I try to delete the class, it works as expected initially:
    Issues an UPDATE to the parent
    Re-reads the generated property
    Deletes the items from the bag


However, it tries to finally DELETE the actual parent and fails since even though it re-read the generated property, it appears not to have set the Version on it, so the final DELETE fails with a concurrency exception:

2008-05-05 07:56:51,430 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened new IDbCommand, open IDbCommands: 1
2008-05-05 07:56:51,430 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Building an IDbCommand object for the SqlString: UPDATE Foo SET FooName = ? WHERE FooId = ? AND VersionInt = ?
2008-05-05 07:56:51,430 [10] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] - Dehydrating entity: [NhibernateTest.Foo#1]
2008-05-05 07:56:51,430 [10] DEBUG NHibernate.Type.StringType [(null)] - binding 'SomeFoo' to parameter: 0
2008-05-05 07:56:51,430 [10] DEBUG NHibernate.Type.Int32Type [(null)] - binding '1' to parameter: 1
2008-05-05 07:56:51,430 [10] DEBUG NHibernate.Type.Int32Type [(null)] - binding '12' to parameter: 2
2008-05-05 07:56:51,430 [10] DEBUG NHibernate.SQL [(null)] - UPDATE Foo SET FooName = @p0 WHERE FooId = @p1 AND VersionInt = @p2; @p0 = 'SomeFoo', @p1 = '1', @p2 = '12'
2008-05-05 07:56:51,430 [10] DEBUG NHibernate.Connection.DriverConnectionProvider [(null)] - Obtaining IDbConnection from Driver
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed IDbCommand, open IDbCommands: 0
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Impl.ConnectionManager [(null)] - skipping aggressive-release due to flush cycle
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened new IDbCommand, open IDbCommands: 1
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Building an IDbCommand object for the SqlString: SELECT foo_.VersionInt as VersionInt0_ FROM Foo foo_ WHERE foo_.FooId=?
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Type.Int32Type [(null)] - binding '1' to parameter: 0
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.SQL [(null)] - SELECT foo_.VersionInt as VersionInt0_ FROM Foo foo_ WHERE foo_.FooId=@p0; @p0 = '1'
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened IDataReader, open IDataReaders: 1
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Type.Int32Type [(null)] - returning '13' as column: VersionInt0_
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Driver.NHybridDataReader [(null)] - running NHybridDataReader.Dispose()
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed IDataReader, open IDataReaders :0
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed IDbCommand, open IDbCommands: 0
2008-05-05 07:56:51,440 [10] DEBUG NHibernate.Impl.ConnectionManager [(null)] - skipping aggressive-release due to flush cycle
2008-05-05 07:56:51,450 [10] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] - Deleting entity: [NhibernateTest.Foo#1]
2008-05-05 07:56:51,450 [10] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] - Version: 12
2008-05-05 07:56:51,450 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Opened new IDbCommand, open IDbCommands: 1
2008-05-05 07:56:51,450 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Building an IDbCommand object for the SqlString: DELETE FROM Foo WHERE FooId = ? AND VersionInt = ?
2008-05-05 07:56:51,450 [10] DEBUG NHibernate.Type.Int32Type [(null)] - binding '1' to parameter: 0
2008-05-05 07:56:51,450 [10] DEBUG NHibernate.Type.Int32Type [(null)] - binding '12' to parameter: 1
2008-05-05 07:56:51,450 [10] DEBUG NHibernate.SQL [(null)] - DELETE FROM Foo WHERE FooId = @p0 AND VersionInt = @p1; @p0 = '1', @p1 = '12'2008-05-05 07:56:51,550 [10] DEBUG NHibernate.Impl.BatcherImpl [(null)] - Closed IDbCommand, open IDbCommands: 0
2008-05-05 07:56:51,550 [10] DEBUG NHibernate.Impl.ConnectionManager [(null)] - skipping aggressive-release due to flush cycle
2008-05-05 07:56:51,560 [10] ERROR NHibernate.Impl.SessionImpl [(null)] - could not synchronize database state with session
NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect) for NhibernateTest.Foo instance with identifier: 1
at NHibernate.Persister.Entity.AbstractEntityPersister.Check(Int32 rows, Object id, Int32 tableNumber, IExpectation expectation, IDbCommand statement) in C:\Anaqua\Anaqua Product\Tools\NHibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 625
at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Int32 j, Object obj, SqlCommandInfo sql, ISessionImplementor session, Object[] loadedState) in C:\Anaqua\Anaqua Product\Tools\NHibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2809
at NHibernate.Persister.Entity.AbstractEntityPersister.Delete(Object id, Object version, Object obj, ISessionImplementor session) in C:\Anaqua\Anaqua Product\Tools\NHibernate\src\NHibernate\Persister\Entity\AbstractEntityPersister.cs:line 2718
at NHibernate.Impl.ScheduledDeletion.Execute() in C:\Anaqua\Anaqua Product\Tools\NHibernate\src\NHibernate\Impl\ScheduledDeletion.cs:line 45
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable) in C:\Anaqua\Anaqua Product\Tools\NHibernate\src\NHibernate\Impl\SessionImpl.cs:line 3280
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list) in C:\Anaqua\Anaqua Product\Tools\NHibernate\src\NHibernate\Impl\SessionImpl.cs:line 3259
at NHibernate.Impl.SessionImpl.Execute() in C:\Anaqua\Anaqua Product\Tools\NHibernate\src\NHibernate\Impl\SessionImpl.cs:line 3218


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.