-->
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.  [ 4 posts ] 
Author Message
 Post subject: Exception on NHibernate Mapping!
PostPosted: Sun Oct 21, 2007 11:05 pm 
Newbie

Joined: Sun Oct 21, 2007 11:00 pm
Posts: 2
Hello, i'm trying to develop a simple NHibernate Console application, but i'm getting an exception as follow:

"Could not compile the mapping document: <directory>\Carro.hbm.xml"

Carro.hbm.xml


Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="Entidades">

  <class name="Carro" table="carro">
    <id name="Id">
      <column name="id" sql-type="Int32" not-null="true"/>
      <generator class="hilo" />
    </id>

    <property name="Descricao">
      <column name="descricao" not-null="true" />
    </property>
    <property name="Fabricante">
      <column name="fabricante" sql-type="Int32"  not-null="true" />
    </property>
  </class>


</hibernate-mapping>


Carro.cs
Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace Entidades
{
    class Carro
    {
        private Int32 id;
        private string descricao;
        private Int32 fabricante;

        public virtual Int32 Id
        {
            get { return id; }
            set { id = value; }
        }

        public virtual string Descricao
        {
            get { return descricao; }
            set { descricao = value; }
        }

        public virtual Int32 Fabricante
        {
            get { return fabricante; }
            set { fabricante = value; }
        }
    }
}


App.config
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <!-- Add this element -->
  <configSections>
    <section
        name="hibernate-configuration"
        type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"
        />
  </configSections>

  <!-- Add this element -->
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="dialect">NHibernate.Dialect.MySQLDialect</property>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
      <property name="connection.connection_string">Server=localhost;Database=hibexamples;User ID=root;Password=123456</property>

    </session-factory>
  </hibernate-configuration>
</configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 22, 2007 12:41 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
Hi,

where did you read, that the attribute "sql-type" exists? If i took a look at the NHibernate documentation there is only a "type" attribute for the column and property mapping.

Regards
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 22, 2007 3:53 am 
Newbie

Joined: Sun Oct 21, 2007 11:00 pm
Posts: 2
luedi wrote:
Hi,

where did you read, that the attribute "sql-type" exists? If i took a look at the NHibernate documentation there is only a "type" attribute for the column and property mapping.

Regards
Klaus


Hi!

I've head there:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#quickstart-mapping,

i think its the new version of cfg-files (xmlns="urn:nhibernate-mapping-2.2")


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 22, 2007 11:04 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
ok, if your using the "sql-type" attribute you have to use the database types. Int32 is an CLR type. If you want to specify the datatype of a property defined in your classes you should use the "type" attribute. In my knowledge it is not absolutely necessary to define data types in your mapping files as NHibernate can determine it via reflection.

Regards
Klaus


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