-->
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.  [ 3 posts ] 
Author Message
 Post subject: Error while saving the record using Nhinernate
PostPosted: Mon Mar 16, 2009 2:14 am 
Newbie

Joined: Mon Mar 16, 2009 2:07 am
Posts: 6
My code is as below:
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernate.Examples");

ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();

User newUser = new User();
newUser.Id = "Joseph_Cool";
newUser.UserName = "Joseph Cool";
newUser.Password = "abc123";
newUser.EmailAddress = "joe@cool.com";
newUser.LastLogon = DateTime.Now;

// Tell NHibernate that this object should be saved
session.Save(newUser);
// commit all of the changes to the DB and close the ISession
transaction.Commit();
session.Close();

I get error at session.save(newUser)..

mapping is as below:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate.Examples.QuickStart.User, NHibernate.Examples"

table="users">
<!--table="[NHibernate].[dbo].[users]">-->
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned"/>
</id>

<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>


i am getting error in the folloing method at bold line:
public object GetIdentifier(object entity)
{
object id;
if (entityMetamodel.IdentifierProperty.IsEmbedded)
{
id = entity;
}
else
{
if (idGetter == null)
{
if (identifierMapperType == null)
{
throw new HibernateException("The class has no identifier property: " + EntityName);
}
else
{
ComponentType copier = (ComponentType)entityMetamodel.IdentifierProperty.Type;
id = copier.Instantiate(EntityMode);
copier.SetPropertyValues(id, identifierMapperType.GetPropertyValues(entity, EntityMode), EntityMode);
}
}
else
{
id = idGetter.Get(entity);
}
}

return id;
}

Please help me out.
I am totally newbie in NHibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 16, 2009 4:50 am 
Regular
Regular

Joined: Wed Feb 11, 2009 10:58 am
Posts: 55
It would surely help to know which error you get.


Top
 Profile  
 
 Post subject: Error is as below:
PostPosted: Mon Mar 16, 2009 10:51 am 
Newbie

Joined: Mon Mar 16, 2009 2:07 am
Posts: 6
"Exception occurred getter of NHibernate.Examples.QuickStart.User.Id"


Message is:
"Object does not match target type."


and the whole stack trace is:

at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target) in c:\dev\OSS\NHibernate\nhibernate\src\NHibernate\Properties\BasicPropertyAccessor.cs:line 201


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