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: No persister for: "*.*.City" name
PostPosted: Thu Dec 10, 2009 4:30 am 
Newbie

Joined: Thu Dec 10, 2009 4:14 am
Posts: 1
Here's my hibernate config file.
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory name="EIMSData.DataObjects">
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">Server=w2jzwzb001;Initial Catalog=EIMSM;Integrated Security=True;</property>
    <property name="show_sql">true</property>       
    <property name="use_outer_join">true</property>
    <property name="show_sql">true</property>
    <property name="proxyfactory.factory_class"> NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu </property>
    <property name="connection.isolation">ReadCommitted</property>
    <property name="use_proxy_validator">true</property>
  </session-factory>
</hibernate-configuration>


This is my table.

Code:
CREATE TABLE [dbo].[CityMaster](
   [CityCode] [int] IDENTITY(1,1) NOT NULL,
   [CityName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
   [DateCreated] [datetime] NOT NULL,
   [DateModified] [datetime] NOT NULL,
CONSTRAINT [PK_CityMaster] PRIMARY KEY CLUSTERED
(
   [CityCode] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


Here's my class file :


Code:
using System;

namespace EIMSData.DataObjects
{
    public class City
    {
        private int _CityCode;
        private string _CityName;
        private DateTime _DateCreated;
        private DateTime _DateModified;


        public int CityCode
        {
            get
            {
                return _CityCode;
            }
            set
            {
                _CityCode = value;
            }
        }

        public string CityName
        {
            get
            {
                return _CityName;
            }
            set
            {
                _CityName = value;
            }
        }

        public DateTime DateCreated
        {
            get
            {
                return _DateCreated;
            }
            set
            {
                _DateCreated = value;
            }
        }

        public DateTime DateModified
        {
            get
            {
                return _DateModified;
            }
            set
            {
                _DateModified = value;
            }
        }
    }
}


And this is my mapping file for the class.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="EIMSData.DataObjects.City, EIMSData.DataObjects" table="CityMaster" >
    <id name="Id" column="CityCode" type="System.Int32" unsaved-value="null">
        <generator class="native"/>
    </id>
    <property name="CityName" column="CityName" access="field.pascalcase-underscore" not-null="true" type="System.String"  length="50" insert="true" update="true"/>
    <property name="DateCreated" column="DateCreated" access="field.pascalcase-underscore" not-null="true" type="System.DateTime"  insert="true" update="true"/>
    <property name="DateModified" column="DateModified" access="field.pascalcase-underscore" not-null="true" type="System.DateTime"  insert="true" update="true"/>
</class>
</hibernate-mapping>


And finally I am getting "No persister for: EIMSData.DataObjects.City" <---- Code causing error. below.

Code:
ISession session;           
            try
            {
                 session = NHibernateHelper.GetCurrentSession();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.ToString());
            }

            ITransaction tx;
            try
            {
                tx = session.BeginTransaction();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.ToString());
            }         
            City newCity = new City();
            newCity.CityName = TextBox1.Text;       
            try
            {
               session.Save(newCity); <---- Code causing error.
            }
            catch (Exception ex)
            {
                throw new Exception(ex.InnerException.ToString());
            }
           
            tx.Commit();
            NHibernateHelper.CloseSession();



My Global.asax has the following code :

Code:
protected void Application_Start(object sender, EventArgs e)
        {
            NHibernate.Cfg.Configuration  config = new NHibernate.Cfg.Configuration();
            config.Configure();
            config.AddClass(typeof(City));

            SessionFactory = config.BuildSessionFactory();
        }


My NHibernateHelper has the following code:

Code:
public sealed class NHibernateHelper
    {
private const string CurrentSessionKey = "nhibernate.current_session";
        private static readonly ISessionFactory sessionFactory;

        static NHibernateHelper()
        {
            sessionFactory = new Configuration().Configure().BuildSessionFactory();
        }

        public static ISession GetCurrentSession()
        {
            HttpContext context = HttpContext.Current;
            ISession currentSession = context.Items[CurrentSessionKey] as ISession;

            if (currentSession == null)
            {
                currentSession = sessionFactory.OpenSession();
                context.Items[CurrentSessionKey] = currentSession;
            }

            return currentSession;
        }

        public static void CloseSession()
        {
            HttpContext context = HttpContext.Current;
            ISession currentSession = context.Items[CurrentSessionKey] as ISession;

            if (currentSession == null)
            {
                // No current session
                return;
            }

            currentSession.Close();
            context.Items.Remove(CurrentSessionKey);
        }

        public static void CloseSessionFactory()
        {
            if (sessionFactory != null)
            {
                sessionFactory.Close();
            }
        }
    }


I have marked my mapping files as "Embedded Resource" and my hibernate file as "Copy always".
Is there anything I need to do to get rid of the error ?
Please let me know if you guys need more details.


Top
 Profile  
 
 Post subject: Re: No persister for: "*.*.City" name
PostPosted: Thu Dec 10, 2009 9:20 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Which version of hibernate ?

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">

should probably be (starting with NHib 1.2):

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

_________________
--Wolfgang


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.