OK so I have the mapping file below now and I get the exception below
that:-) What am I doing wrong?


<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="HelloWorldNHibernate"
                   assembly="HelloWorldNHibernate">

  <!-- Mappings for class 'Customer' -->
  <class name="HelloWorldNHibernate.Customer"
         table="Customers"
         lazy="false"
         dynamic-insert="true">

    <id>
      <column name="CustID" />
      <generator class="identity" />
    </id>

    <property name="FirstName" />
    <property name="LastName" />

  </class>

</hibernate-mapping>






System.TypeInitializationException was unhandled
  Message="The type initializer for
'HelloWorldNHibernate.NHibernateManager' threw an exception."
  Source="HelloWorldNHibernate"
  TypeName="HelloWorldNHibernate.NHibernateManager"
  StackTrace:
       at HelloWorldNHibernate.NHibernateManager..ctor()
       at HelloWorldNHibernate.Program.Main() in C:\Documents and
Settings\yonatan\My Documents\Visual Studio 2008\Projects
\HelloWorldNHibernate\HelloWorldNHibernate\Program.cs:line 21
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String
[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
       at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
       at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: NHibernate.MappingException
       Message="Could not compile the mapping document:
HelloWorldNNHibernate.Models.Customer.hbm.xml"
       Source="NHibernate"
       StackTrace:
            at NHibernate.Cfg.Configuration.LogAndThrow
(MappingException me)
            at NHibernate.Cfg.Configuration.AddValidatedDocument
(XmlDocument doc, String name)
            at NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader
hbmReader, String name)
            at NHibernate.Cfg.Configuration.AddInputStream(Stream
xmlInputStream, String name)
            at NHibernate.Cfg.Configuration.AddResource(String path,
Assembly assembly)
            at NHibernate.Cfg.Configuration.AddResources(Assembly
assembly, IList resources, Boolean skipOrdering)
            at NHibernate.Cfg.Configuration.AddAssembly(Assembly
assembly, Boolean skipOrdering)
            at NHibernate.Cfg.Configuration.AddAssembly(Assembly
assembly)
            at NHibernate.Cfg.Configuration.AddAssembly(String
assemblyName)
            at HelloWorldNHibernate.NHibernateManager..cctor() in C:
\Documents and Settings\yonatan\My Documents\Visual Studio
2008\Projects\HelloWorldNHibernate\HelloWorldNHibernate\Utils
\NHibernateManager.cs:line 22
       InnerException: NHibernate.MappingException
            Message="must specify an identifier type: Customer"
            Source="NHibernate"
            StackTrace:
                 at NHibernate.Cfg.HbmBinder.BindRootClass(XmlNode
node, RootClass model, Mappings mappings)
                 at NHibernate.Cfg.HbmBinder.BindRoot(XmlDocument doc,
Mappings mappings)
                 at NHibernate.Cfg.Configuration.AddValidatedDocument
(XmlDocument doc, String name)
            InnerException:









On Nov 19, 11:01 am, Diego Mijelshon <[email protected]> wrote:
> You *have* to map the Id, but you are not required to have a property for
> it.
>
>  <class
> name="HelloWorldNHibernate.Customer" table="Customers" lazy="false"
> dynamic-insert="true">
>    *<id column="id_col_name" type="id_col_type">*
> *      <generator class="identity"/>*
> *   </id>*
>    <property name="FirstName" />
>    <property name="LastName" />
>  </class>
>
>    Diego
>
>
>
> On Thu, Nov 19, 2009 at 05:53, code_blocker <[email protected]> wrote:
> > hi,
>
> > Say I have an object relational mapping. The database table has an
> > identity column but I don't want to include this information in my
> > object. How would I implement this?
>
> > The code (which I thought should work but doesn't) for the class
> > Customer and its mapping file are below:
>
> > class Customer
> >    {
> >        # region Decalarations
> >        private String p_FirstName = String.Empty;
> >        private String p_LastName = String.Empty;
> >        #endregion
>
> >        #region Constructor
> >        public Customer() { }
>
> >        public Customer(String FirstName, String LastName)
> >        {
> >            p_FirstName = FirstName;
> >            p_LastName = LastName;
> >        }
> >        #endregion
>
> >        # region Properties
> >        public virtual String FirstName
> >        {
> >            get { return p_FirstName; }
> >            set { p_FirstName = value; }
> >        }
>
> >        public virtual String LastName
> >        {
> >            get { return p_LastName; }
> >            set { p_LastName = value; }
> >        }
> >        # endregion
> >    }
>
> > <?xml version="1.0"?>
> > <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
> >                   namespace="HelloWorldNHibernate"
> >                   assembly="HelloWorldNHibernate">
>
> >  <!-- Mappings for class 'Customer' -->
> >  <class name="HelloWorldNHibernate.Customer"
> >         table="Customers"
> >         lazy="false"
> >         dynamic-insert="true">
>
> >    <property name="FirstName" />
> >    <property name="LastName" />
>
> >  </class>
>
> > </hibernate-mapping>
>
> > --
>
> > You received this message because you are subscribed to the Google Groups
> > "nhusers" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<nhusers%[email protected]­>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nhusers?hl=.- Hide quoted text -
>
> - Show quoted text -

--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=.


Reply via email to