-->
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: Getting 'NHibernate.ADOException' while Saving Data.
PostPosted: Thu Jul 12, 2007 1:18 am 
Newbie

Joined: Thu Jul 12, 2007 1:13 am
Posts: 17
Hello,
I'm using NHibernate 1.2.0 and while saving data I'm getting an exception 'NHibernate.ADOException'
and it reads:
could not insert: [NHDemo.User#2][SQL: INSERT INTO USERS (Name, Password, EmailAddress, LastLogon, LoginId) VALUES (?, ?, ?, ?, ?)]

below is the mapping class file:
Code:
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate.Mapping.Attributes;
using Nullables.NHibernate;
using Nullables;
namespace NHDemo
{
    [NHibernate.Mapping.Attributes.Class(Table = "USERS")]
    public class User
    {
        private int logonID;
        private string userName;
        private string password;
        private string emailAddress;
        private DateTime lastLogon;


        public User()
        {
        }

        [NHibernate.Mapping.Attributes.Id(1,Column = "LoginId", Name = "LogonID", TypeType = typeof(Int32))]
        [NHibernate.Mapping.Attributes.Generator(2, Class = "assigned")]
         [Param(3, Name = "assigned")]
        public virtual int LogonID
        {
            get { return logonID; }
            set { logonID = value; }
        }
        [NHibernate.Mapping.Attributes.Property(Column = "Name", TypeType = typeof(String),Length = 40)]
        public virtual string UserName
        {
            get { return userName; }
            set { userName = value; }
        }
        [NHibernate.Mapping.Attributes.Property(Column = "Password", TypeType = typeof(String), Length = 20)]
        public virtual string Password
        {
            get { return password; }
            set { password = value; }
        }
        [NHibernate.Mapping.Attributes.Property(Column = "EmailAddress", TypeType = typeof(String), Length = 40)]
        public virtual string EmailAddress
        {
            get { return emailAddress; }
            set { emailAddress = value; }
        }
        [NHibernate.Mapping.Attributes.Property(Column = "LastLogon", TypeType = typeof(DateTime))]
        public virtual DateTime LastLogon
        {
            get { return lastLogon; }
            set { lastLogon = value; }
        }
       
    }
}


Code:
Configuration conf = new Configuration();
            conf.AddAssembly("NHDemo");
            NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize("", System.Reflection.Assembly.GetExecutingAssembly());
            conf.AddXmlFile("User.hbm.xml");
            ISessionFactory factory = conf.BuildSessionFactory();
            //cfg.AddXmlFile("User.hbm.xml");
            ISession session = factory.OpenSession();
            //User joseph = (User)session.Load(typeof(User),1);
            ITransaction transaction = session.BeginTransaction();
            NHDemo.User newUser = new NHDemo.User();
            newUser.LogonID = 2;
            newUser.UserName = "Joseph Cool";
            newUser.Password = "abc123";
            newUser.EmailAddress = "joe@cool.com";
            newUser.LastLogon = DateTime.Now;

            session.Save(newUser);
           
            // commit all of the changes to the DB and close the ISession
            transaction.Commit(); [b]//This is the place where I'm getting Exception[/b]
            session.Close();

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html
Code:


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.