-->
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.  [ 2 posts ] 
Author Message
 Post subject: Application just dies without inserting data No errors found
PostPosted: Fri Jul 13, 2007 4:52 pm 
Newbie

Joined: Fri Jul 13, 2007 1:36 pm
Posts: 6
I am running a simple application and right before assigning the properties the application dies. Meaning it just snap out of the debug mode and does nothing. No errors are thrown.

I am using Console App with a class library.

Here is the App.config of the console app:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<configSections>
<section
name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</configSections>

<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2000Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=localhost;Database=School;Trusted_Connection=true"
/>
</nhibernate>


</configuration>


Now here is the simple "Customer" class:


using System;
using System.Collections.Generic;
using System.Text;

namespace MyCustomObjects
{
public class Customer
{
private int _customerID;
private string _firstName;
private string _lastName;

public virtual int CustomerID
{
get { return _customerID; }
set { _customerID = value; }
}

public virtual string FirstName
{
get { return _firstName; }
set { _firstName = value; }
}

public virtual string LastName
{
get { return _lastName; }
set { _lastName = value; }
}

public virtual bool Save()
{
CustomerManager.Save(this);

return false;
}

}
}

NOTE: For some reason I have to make all the properties virtual :(


Here is the hbm.xml file:

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="MyCustomObjects.Customer, MyCustomObjects"
table="Customers">
<id name="CustomerID"
type="Int32">
<generator class="assigned" />
</id>
<property name="FirstName"
type="String" length="40"/>
<property name="LastName"
type="String" length="30"/>
</class>
</hibernate-mapping>


And here is the code used to insert the data:

public static int Save(Customer customer)
{
try
{

Configuration config = new Configuration();

config.AddAssembly("MyCustomObjects");

ISessionFactory factory = config.BuildSessionFactory();

ISession session = factory.OpenSession();

session.Save(customer);

session.Close();

}
catch (Exception ex)
{
string exception = ex.Message + " " + ex.InnerException.Message;
}

return 1;
}


The application dies at session.Save(customer) method.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 5:03 pm 
Newbie

Joined: Fri Jul 13, 2007 1:36 pm
Posts: 6
Found the solution. I was not inserting into one of the required columns. I hoped for an exception to be thrown at that point.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.