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: need help urgently in nhibernate
PostPosted: Thu Sep 20, 2007 8:08 am 
Newbie

Joined: Thu Sep 20, 2007 7:48 am
Posts: 6
i am working with nhibernate ,

In my project i have made a class



namespace NHibernateExercise
{
[NHibernate.Mapping.Attributes.Class(0, Name = "NHibernateExercise.Car", Table = "Car")]
public class Car
{
private string carNo;
[NHibernate.Mapping.Attributes.Property(1,Name="CarNo",Column="CarNo", Type= "string",NotNull=true)]
public string CarNo
{
get { return carNo; }
}

}
}


and i am have modified hibernate.cfg.xml to support the database i need


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

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="NHibernateExercise">
<property name="connection.connection_string">Server=XXXXX;Port=1234;Provider=Sybase.Data.AseClient;Initial Catalog=AAA; Data Source=AAA;User ID=aa;Password=****</property>
<property name="show_sql">false</property>
<property name="dialect">NHibernate.Dialect.SybaseDialect</property>
<property name="user_outer_join">true</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N' </property>
<mapping assembly="NHibernateExercise"/>

</session-factory>

</hibernate-configuration>


now the class that uses these is

public class CarProcessor
{

private const string CurrentSession="nhibernate.current_session";
public static void Main(string[] args)
{

try
{

ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
ISession session = sessionFactory.OpenSession();
ITransaction transaction = session.BeginTransaction();
bool available = session.IsConnected;

Car car = new Car();
car= (Car)session.Load(Type.GetType("Car"), "123");


transaction.Commit();
session.Close();
sessionFactory.Close();


}
catch (Exception e)
{
string exp = e.ToString();
}
}
}

when i run this file i got the following exception on "car= (Car)session.Load(Type.GetType("Car"), "123");"



System.NullReferenceException: Object reference not set to an instance of an object.
at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation)
at NHibernate.Impl.SessionImpl.Load(Type clazz, Object id)



the value of session.IsConnected it true that means it is connected to DB but the persistant object is not found or null or some other reason is there.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 20, 2007 10:10 am 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Type.GetType() requires an assembly-qualified name. Use either typeof(Car) or use the generic overload for Load that takes the type as a generic argument if you're using .NET 2.0.

I.e. if you are using .NET 1.x, use:
Code:
car = (Car)session.Load(typeof(Car), "123");

If you are using .NET 2.0, you can use the cleaner generic call:
Code:
car = session.Load<Car>("123");


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.