-->
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: Neophyte issues with NHibernate.MappingException
PostPosted: Thu Nov 17, 2005 12:37 am 
Newbie

Joined: Wed Nov 16, 2005 11:01 pm
Posts: 4
Hello,

Trying to come to grips with NHibernate, and am in need of a poke in the right direction. The NHibernateEg TutorialA compiles and runs locally without issue.

I've mapped our database using a templating tool - "MyGeneration" - with the "NHibernate OM - 0.7.1" template, all seems ok, I have double checked "Embedded Resource" flag is set on all <table>.hbm.xml files, but can't seem to get past this exception:

Quote:
NHibernate.MappingException was unhandled
Message="The element 'class' in namespace 'urn:nhibernate-mapping-2.0' has invalid child element 'property' in namespace 'urn:nhibernate-mapping-2.0'. List of possible elements expected: 'urn:nhibernate-mapping-2.0:meta urn:nhibernate-mapping-2.0:jcs-cache urn:nhibernate-mapping-2.0:cache urn:nhibernate-mapping-2.0:id urn:nhibernate-mapping-2.0:composite-id'."
Source="NHibernate"
StackTrace:
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream)
...etc...


An example mapping file:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="InterActiveHealth.Data.Application,InterActiveHealth.Data" table="Application">

      <id name="ApplicationId" column="Application_ID" type="String">
         <generator class="assigned"/>
      </id>
      <property column="Name" type="String" name="Name" not-null="true" length="50" />
      <property column="Purpose" type="String" name="Purpose" not-null="true" length="255" />
...etc...      
   </class>
</hibernate-mapping>

My test is just a simple console app:

Code:
using InterActiveHealth.Data;
using NHibernate;
using NHibernate.Cfg;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Starting Test");

            Configuration configuration = new Configuration();
               
            configuration.AddAssembly("InterActiveHealth.Data"); // <-- MappingException



Any clues please? It appears to be a schema issue, but how can I stuff that up when the manual says:

Quote:
All XML mappings have to use the nhibernate-mapping-2.0 schema. The actual schema may be found in the NHibernate source directory, or as an Embedded Resource in NHibernate.dll. NHibernate will always use the Embedded Resource as the source for the schema.


I'm sure it's something simple :roll:

cheers
si


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 6:29 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Elements in the mapping file have to follow specific order sometimes. You have to have an <id> or <composite-id> first, then <property> elements. The mapping you pasted is ok, maybe there is another mapping that has the wrong order?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 8:40 am 
Newbie

Joined: Wed Nov 16, 2005 11:01 pm
Posts: 4
sergey wrote:
Elements in the mapping file have to follow specific order sometimes. You have to have an <id> or <composite-id> first, then <property> elements. The mapping you pasted is ok, maybe there is another mapping that has the wrong order?


Thank you very much Sergey!

We're about 90% through conversion from Sybase to SQL Server (I was testing against the new db schema) and a couple of tables out of the 100 didn't have primary key defined, hence the template engine missed <id> or <composite-id> element.

Of course, with 20-20 hindsight the exception makes perfect sense :)

It's approaching midnight here but I just had to VPN back into work to see if that fixed the problem, and it did, 'tis working fine now...so THANK YOU!

peace
si


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.