Help! NHibernate data saving problem.
-
Hi, I am in the trouber of the error while the project trys to saving the data to child table. The error message is shown below: NHibernate.ADOException: could not insert: [ConsoleApplication1.user][SQL: INSERT INTO user (UNAME, NID) VALUES (?, ?)] ---> So confused that why it cannot get values to save. NHibernate I used is version 1.2. The code files are list below, please help me out here. Thanks in advance. app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.2.0.4000,Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </configSections> <nhibernate> <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/> <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect"/> <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/> <add key="hibernate.connection.connection_string" value="Server=;initial catalog=;Persist Security Info=True;User ID=;Password="/> </nhibernate> </configuration> user.hbm.xml: <hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2"> <class name="ConsoleApplication1.user, ConsoleApplication1" table="user"> <id name="UID" type="System.Int32" column="UID" unsaved-value="0"> <generator class="native" /> </id> <property name="UNAME" type="System.String" column="UNAME" not-null="false" /> <many-to-one name="Nationality" class="ConsoleApplication1.nationality, ConsoleApplication1" fetch="select" cascade="all"> <column name="NID" not-null="false" /> </many-to-one> </class> </hibernate-mapping> user.hbm.cs: namespace ConsoleApplication1 { [System.SerializableAttribute()] public class Abstractuser { private int uID; private string uNAME; private ConsoleApplication1.nationality nationality; public virtual int UID { get { return this.uID; } set { this.uID = value; } } public virtual string UNAME { get { return this.uNAME; } set { this.uNAME = value;
-
Hi, I am in the trouber of the error while the project trys to saving the data to child table. The error message is shown below: NHibernate.ADOException: could not insert: [ConsoleApplication1.user][SQL: INSERT INTO user (UNAME, NID) VALUES (?, ?)] ---> So confused that why it cannot get values to save. NHibernate I used is version 1.2. The code files are list below, please help me out here. Thanks in advance. app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.2.0.4000,Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </configSections> <nhibernate> <add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/> <add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect"/> <add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/> <add key="hibernate.connection.connection_string" value="Server=;initial catalog=;Persist Security Info=True;User ID=;Password="/> </nhibernate> </configuration> user.hbm.xml: <hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2"> <class name="ConsoleApplication1.user, ConsoleApplication1" table="user"> <id name="UID" type="System.Int32" column="UID" unsaved-value="0"> <generator class="native" /> </id> <property name="UNAME" type="System.String" column="UNAME" not-null="false" /> <many-to-one name="Nationality" class="ConsoleApplication1.nationality, ConsoleApplication1" fetch="select" cascade="all"> <column name="NID" not-null="false" /> </many-to-one> </class> </hibernate-mapping> user.hbm.cs: namespace ConsoleApplication1 { [System.SerializableAttribute()] public class Abstractuser { private int uID; private string uNAME; private ConsoleApplication1.nationality nationality; public virtual int UID { get { return this.uID; } set { this.uID = value; } } public virtual string UNAME { get { return this.uNAME; } set { this.uNAME = value;
Harry Sun wrote:
NHibernate.ADOException: could not insert: [ConsoleApplication1.user][SQL: INSERT INTO user (UNAME, NID) VALUES (?, ?)]
Those question-marks are parameter placeholders. You are using generator=Native... is your UID column set to Identity? Otherwise check the InnerException property.
Mark Churchill Director Dunn & Churchill Free Download:
Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio. -
Harry Sun wrote:
NHibernate.ADOException: could not insert: [ConsoleApplication1.user][SQL: INSERT INTO user (UNAME, NID) VALUES (?, ?)]
Those question-marks are parameter placeholders. You are using generator=Native... is your UID column set to Identity? Otherwise check the InnerException property.
Mark Churchill Director Dunn & Churchill Free Download:
Diamond Binding: The simple, powerful, reliable, and effective data layer toolkit for Visual Studio.