Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Help! NHibernate data saving problem.

Help! NHibernate data saving problem.

Scheduled Pinned Locked Moved Design and Architecture
helpc++javadatabasesysadmin
3 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harry Sun
    wrote on last edited by
    #1

    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;

    M 1 Reply Last reply
    0
    • H Harry Sun

      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;

      M Offline
      M Offline
      Mark Churchill
      wrote on last edited by
      #2

      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.

      H 1 Reply Last reply
      0
      • M Mark Churchill

        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.

        H Offline
        H Offline
        Harry Sun
        wrote on last edited by
        #3

        Thank you for your reply. I know I did something terrible, just because was not for sure which catalogue this question should be in. I will never do that again. Thanks again. Please forgive me.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups