NullSafeSet is called with incorrect index
Description
Environment
Attachments
Activity
robsosno January 18, 2009 at 10:11 AM
I've repeated my test with hibernate and java.
I've got much more descriptive error message:
Exception in thread "main" org.hibernate.MappingException: Repeated column in mapping for entity: hibtest.VirtualCardNumber column: number (should be mapped with insert="false" update="false")
instead of cryptic "Incorrect index" in NHibernate.
I've removed "Number" property which contains repeated column. There were no problems and test finished succesfully.
Then I've come back to test program in C#. It worked without a Number column correctly. Then I've returned to the bigger application I'm working on. There were also no problems.
Number property was obviously excessive. I can't explain why I couldn't remove it earlier.
Anyway issue can be closed.
robsosno December 20, 2008 at 4:43 AM
I was a bit tired so it seemed that I've found a solution.
Actually I cannot delete property "Number" from mapping: "real" database raises an error: "property-ref [Number] not found on entity [DomainModel.VirtualCardNumber]"
From unknown reasons SQLite.NET doesn't issue this.
I'm attaching my small test project linked with SQLite.NET showing the issue.
Tuna Toksoz December 19, 2008 at 1:10 PM
May I close the issue?
robsosno December 19, 2008 at 1:07 PM
I've found reason of the problem. Correct mapping is following:
<class name="Propertyref.VirtualCardNumber,Propertyref" table="virtualcardnumbers" lazy="true" mutable="false">
<id name="Serno" access="property" column="serno" type="int" unsaved-value="0">
<generator class="native" />
</id>
<property type="string" access="property" length="16" name="Vnumber" column="vnumber" />
<property type="string" access="property" length="16" name="Mnumber" column="mnumber" />
<many-to-one name="Card" cascade="none" column="number" access="property" property-ref="Number"/>
robsosno December 19, 2008 at 9:49 AM
Additional data:
I've changed TString to standard string type. The Odbc error remains the same. I've verified that it occurs with SQLite.NET database too (so IdentityInsertString doesn't matter because it doesn't exist in SQLite).
An error occurs when many-to-one have "property-ref" clause.
My mappings are:
<class name="DomainModel.VirtualCardNumber,DomainModel" table="virtualcardnumbers" lazy="true" mutable="true">
<id name="Serno" access="property" column="serno" type="int" unsaved-value="0">
<generator class="native" />
</id>
<property type="HibernateDao.TString,HibernateDao" access="property" length="16" name="Number" column="number" />
<property type="HibernateDao.TString,HibernateDao" access="property" length="16" name="Vnumber" column="vnumber" />
<property type="HibernateDao.TString,HibernateDao" access="property" length="16" name="Mnumber" column="mnumber" />
<many-to-one name="Card" cascade="none" column="number" property-ref="Number" />
<class name="DomainModel.Card,DomainModel" table="cardx" lazy="true" mutable="true">
<id name="Serno" access="property" column="serno" type="int" unsaved-value="0">
<generator class="native" />
</id>
<property type="string" access="property" not-null="true" length="25" name="Number" column="number" />
Test program is:
VirtualCardNumber vcn = new VirtualCardNumber();
vcn.Mnumber="479084******9536";
vcn.Number="479084XXXXXX9536";
vcn.Vnumber = "479084P000001953";
vcn.Serno = 1;
vcn.Card = new Card();
vcn.Card.Serno = 1;
vcn.Card.Number = "479084XXXXXX9536";
session.Save(vcn);
I'm using simple user type TString which is used instead of string to trim trailing spaces.
For all read operations it works fine. For write operations which does not have identity column it works fine.
However when object is saved to the table containing identity column an index parameter has incorrect value.
In my particular case I see that NullSafeSet(System.Data.IDbCommand cmd, object value, int index)
is called with following:
cmd.CommandText = "INSERT INTO virtualcardnumbers (serno, vnumber, mnumber, number) VALUES (0, ?, ?, ?)"
value = "479084******9536"
index = 3
and then I'm getting "Incorrect index 3 for this element OdbcParameterCollection: Count=3." from NHibernateUtil.String.NullSafeSet.
Column serno is an identity column. Value 0 comes from IdentityInsertString provided by the dialect (IfxDialect).
This error however belongs to the core (not dialect or user type).
Attached exception details.