Click here to Skip to main content
15,887,268 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
GeneralRe: Using Team Foundation in Multiple Environments? Pin
Jasmine25011-Feb-08 5:29
Jasmine25011-Feb-08 5:29 
AnswerRe: Using Team Foundation in Multiple Environments? Pin
led mike1-Feb-08 4:45
led mike1-Feb-08 4:45 
QuestionAn MVP Variant? Pin
Philip Laureano31-Jan-08 6:15
Philip Laureano31-Jan-08 6:15 
AnswerRe: An MVP Variant? Pin
Jasmine250131-Jan-08 10:48
Jasmine250131-Jan-08 10:48 
GeneralRe: An MVP Variant? Pin
Philip Laureano31-Jan-08 11:22
Philip Laureano31-Jan-08 11:22 
GeneralRe: An MVP Variant? Pin
Jasmine250131-Jan-08 11:56
Jasmine250131-Jan-08 11:56 
AnswerRe: An MVP Variant? Pin
Pete O'Hanlon1-Feb-08 3:40
mvePete O'Hanlon1-Feb-08 3:40 
GeneralHelp! NHibernate data saving problem. Pin
Harry Sun29-Jan-08 22:58
Harry Sun29-Jan-08 22:58 
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;
}
}

public virtual ConsoleApplication1.nationality Nationality {
get {
return this.nationality;
}
set {
this.nationality = value;
}
}
}

[System.SerializableAttribute()]
public partial class user : Abstractuser {
}
}

nationality.hbm.xml:

<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2">
<class name="ConsoleApplication1.nationality, ConsoleApplication1" table="nationality">
<id name="NID" type="System.Int32" column="NID" unsaved-value="0">
<generator class="native" />
</id>
<property name="NATIONALITY" type="System.String" column="NATIONALITY" not-null="false" />
<bag name="User" inverse="true" lazy="true" cascade="all">
<key>
<column name="NID" not-null="false" />
</key>
<one-to-many class="ConsoleApplication1.user, ConsoleApplication1" />
</bag>
</class>
</hibernate-mapping>

nationality.hbm.cs:

namespace ConsoleApplication1 {


[System.SerializableAttribute()]
[System.Xml.Serialization.XmlIncludeAttribute(typeof(ConsoleApplication1.user))]
[System.Xml.Serialization.SoapIncludeAttribute(typeof(ConsoleApplication1.user))]
public class Abstractnationality {

private int nID;

private string nATIONALITY;

private System.Collections.IList user;

public virtual int NID {
get {
return this.nID;
}
set {
this.nID = value;
}
}

public virtual string NATIONALITY {
get {
return this.nATIONALITY;
}
set {
this.nATIONALITY = value;
}
}

public virtual System.Collections.IList User {
get {
return this.user;
}
set {
this.user = value;
}
}
}

[System.SerializableAttribute()]
public partial class nationality : Abstractnationality {
}
}

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

NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddAssembly("ConsoleApplication1");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();


nationality nat = (nationality)session.Get(typeof(nationality), 1);

user u = new user();
u.UNAME = "Pall";
u.Nationality = nat;
nat.User.Add(u);

try
{
if (!session.IsConnected)
{
session.Reconnect();
}

session.Save(u); // Error occured at this line!!

transaction.Commit();
session.Close();
}
catch (Exception e)
{
string s = e.ToString();
}
}


}
}
GeneralRe: Help! NHibernate data saving problem. Pin
Mark Churchill30-Jan-08 2:05
Mark Churchill30-Jan-08 2:05 
GeneralRe: Help! NHibernate data saving problem. Pin
Harry Sun30-Jan-08 16:59
Harry Sun30-Jan-08 16:59 
Generalshape locations Pin
netJP12L29-Jan-08 6:50
netJP12L29-Jan-08 6:50 
GeneralUnrelated data layer question. Pin
MatthewSmith27-Jan-08 9:35
MatthewSmith27-Jan-08 9:35 
GeneralRe: Unrelated data layer question. Pin
led mike28-Jan-08 6:13
led mike28-Jan-08 6:13 
GeneralRe: Unrelated data layer question. Pin
MatthewSmith28-Jan-08 7:34
MatthewSmith28-Jan-08 7:34 
GeneralRe: Unrelated data layer question. Pin
led mike28-Jan-08 8:34
led mike28-Jan-08 8:34 
GeneralRe: Unrelated data layer question. Pin
Mark Churchill28-Jan-08 20:11
Mark Churchill28-Jan-08 20:11 
GeneralRe: Unrelated data layer question. Pin
dojohansen11-Feb-08 8:10
dojohansen11-Feb-08 8:10 
GeneralRe: Unrelated data layer question. Pin
dojohansen11-Feb-08 8:04
dojohansen11-Feb-08 8:04 
GeneralDAL Design Question Pin
Waleed Eissa24-Jan-08 2:42
Waleed Eissa24-Jan-08 2:42 
GeneralRe: DAL Design Question Pin
Mark Churchill25-Jan-08 4:24
Mark Churchill25-Jan-08 4:24 
GeneralRe: DAL Design Question Pin
led mike25-Jan-08 4:40
led mike25-Jan-08 4:40 
GeneralRe: DAL Design Question Pin
Mark Churchill25-Jan-08 4:55
Mark Churchill25-Jan-08 4:55 
GeneralRe: DAL Design Question Pin
Waleed Eissa27-Jan-08 3:16
Waleed Eissa27-Jan-08 3:16 
GeneralRe: DAL Design Question Pin
Mark Churchill27-Jan-08 5:19
Mark Churchill27-Jan-08 5:19 
GeneralRe: DAL Design Question Pin
Waleed Eissa1-Feb-08 18:58
Waleed Eissa1-Feb-08 18:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.