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: Possible Bug in version 1.0.2 (MS SQLServer)
PostPosted: Wed Jul 19, 2006 9:29 am 
Newbie

Joined: Wed Apr 26, 2006 5:28 am
Posts: 18
Hibernate version: 1.0.2

Mapping documents:
Help:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Help.Data" assembly="Help">
<class name="Help" table="Help">
<meta attribute="field-prefix">m_</meta>
<composite-id>
<key-property name="Application" type="string">
<column name="Application" sql-type="varchar(30)" not-null="true"/>
</key-property>
<key-many-to-one name="ApplicationType" class="ApplicationType">
<column name="ApplicationType" sql-type="int" not-null="false"/>
</key-many-to-one>
</composite-id>
<property name="URL" type="string" not-null="false">
<column name="Url" sql-type="varchar(250)" not-null="false"/>
</property>
<component name="Help" class="HelpSet">
<many-to-one name="Help" class="HelpText">
<column name="HelpTextId" sql-type="int" not-null="false"/>
</many-to-one>
<many-to-one name="ShortHelp" class="HelpText">
<column name="ShortHelpTextId" sql-type="int" not-null="false"/>
</many-to-one>
</component>
</class>
</hibernate-mapping>


ApplicationType
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Help.Data" assembly="Help">
<class name="ApplicationType" table="ApplicationType">
<meta attribute="field-prefix">m_</meta>
<id name="Id" type="System.Int32" unsaved-value="-1">
<column name="Id" sql-type="int" not-null="true"/>
<generator class="identity" />
</id>
<property name="Description" type="string">
<column name="Description" sql-type="varchar(50)" not-null="true"/>
</property>
</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:
NHibernate.HibernateException: SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 0). Possible causes: the row was modified or deleted by another user, or a trigger is reporting misleading row count.
at NHibernate.Impl.NonBatchingBatcher.AddToBatch(Int32 expectedRowCount)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Boolean[] includeProperty, Object oldVersion, Object obj, SqlString sqlUpdateString, ISessionImplementor session)
at NHibernate.Persister.EntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Object[] oldFields, Object oldVersion, Object obj, ISessionImplementor session)
at NHibernate.Impl.ScheduledUpdate.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at HilfeTexte.Data.NHibernateHelper.Save(Object data) in C:\Projects\Help\Help\Data\NHibernateHelper.cs:line 165

Name and version of the database you are using:
Microsoft SQL Server 2000

The generated SQL (show_sql=true):
UPDATE Help SET HelpTextId = @p0, ShortHelpTextId = @p1, Url = @p2 WHERE Application = @p3 AND ApplicationType = @p4

Debug level Hibernate log excerpt:
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.Type.Int32Type - binding '11' to parameter: 0
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.Type.Int32Type - binding '10' to parameter: 1
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.Type.StringType - binding 'www.some-url.com' to parameter: 2
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.Type.StringType - binding 'MyApplication' to parameter: 3
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.Type.Int32Type - binding null to parameter: 4
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.SQL - UPDATE Help SET HelpTextId = @p0, ShortHelpTextId = @p1, Url = @p2 WHERE Application = @p3 AND ApplicationType = @p4
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.SQL - @p0 = '11'
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.SQL - @p1 = '10'
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.SQL - @p2 = 'www.some-url.com'
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.SQL - @p3 = 'MyApplication'
2006-07-19 15:03:48,187 [3440] DEBUG NHibernate.SQL - @p4 = ''


Hello,

I think I found a possible bug. The exception from above occurs because this where clause is used:
WHERE Application = @p3 AND ApplicationType = @p4

Parameter @p4 is null but whe you create an SQL statement for a SQL Server and a null value is in the where clause it must use the "is" keyword instead of =

For example the sql statement from above corrected like that:
UPDATE Help SET HelpTextId = @p0, ShortHelpTextId = @p1, Url = @p2 WHERE Application = @p3 AND ApplicationType IS @p4
works perfect.

Is this a bug or can I make corrections in the mapping file?

Kind regards.

NCC-1701-M

P.S.:
At the database the Application is the primary key and for Application and ApplicationType exists an unique index. I couldn't create a composite primary key because primary keys couldn't be null and ApplicationType can be null (because if the value is null it's valid for all combinations of Application and ApplicationType).

_________________
=/\=

Live long and prosper


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.