-->
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.  [ 4 posts ] 
Author Message
 Post subject: No row with the given identifier exists.
PostPosted: Thu May 21, 2009 8:34 am 
Newbie

Joined: Fri Mar 13, 2009 10:23 am
Posts: 10
Hi all,

I'm runing an NHibernate program, i want it to save the customer details into the database but I get "No row with the given identifier exists[NHibernate_Demo.Customer#10]" error. I got some of the code from the net and other stuff I don't understand as I'm new in NHibernate concept.

Here is my Customer.cs class:

using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Diagnostics;

namespace NHibernate_Demo
{

class Program
{
static void Main(string[] args)
{

//Console.WriteLine("Hello there!");
Console.Write("Please input your ID: ");
string CustomerID = Console.ReadLine();

Console.Write("Please input your Company Name: ");
string CompanyName = Console.ReadLine();

Console.Write("Please input your Name: ");
string ContactName = Console.ReadLine();

Console.Write("Please input your Title: ");
string ContactTitle = Console.ReadLine();

Console.Write("Please input your Phone: ");
string Phone = Console.ReadLine();

Console.Write("Please input your Alt Phone: ");
string AltPhone = Console.ReadLine();

Console.WriteLine("Hello " + ContactName + ". Thank you for registering your
information.");
Console.Read();

// Loads the NHibernate Types to prepare for Serialization
Configuration cfg = new Configuration();
cfg.Configure();

cfg.AddAssembly(typeof(NHibernate_Demo.Customer).Assembly);
//cfg.AddClass(typeof(Customer));
//cfg.AddFile("Customer.hbm.xml");

//Opens a session to NHiberbate to allow us to work with objects
ISessionFactory sessionsF = cfg.BuildSessionFactory();

//let ISessiionFactory open connection
ISession sessionS = sessionsF.OpenSession();

ITransaction transaction = sessionS.BeginTransaction();
{

Customer customer = (Customer)sessionS.Load(typeof(Customer), 12);
sessionS.Close();


}

}

}

}

I get an error on this line and I got it from the net.

Customer customer = (Customer)sessionS.Load(typeof(Customer), 12);

I really don't know what to put there for my program to save to the database.

Please, I'd appreciate a solution to this or some hints on what to do.

Thanks.


Top
 Profile  
 
 Post subject: Re: No row with the given identifier exists.
PostPosted: Thu May 21, 2009 10:50 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You're trying to load an object which does not exist. Your code does no saving !

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: No row with the given identifier exists.
PostPosted: Thu May 21, 2009 11:04 am 
Newbie

Joined: Fri Mar 13, 2009 10:23 am
Posts: 10
ok. How do I write a code that will save the details into the database?


Top
 Profile  
 
 Post subject: Re: No row with the given identifier exists.
PostPosted: Thu May 21, 2009 11:18 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I recommend startung with this:

http://nhforge.org/wikis/howtonh/your-first-nhibernate-based-application.aspx

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

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.