A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll

2,546 views
Skip to first unread message

Niclas Pehrsson

unread,
Jun 25, 2008, 6:56:38 AM6/25/08
to nhusers
This produces A first chance exception of type
'NHibernate.MappingException' occurred in NHibernate.dll in the output
window, the application works fine, but I dont like exceptions. What
can be wrong?

<many-to-one name="Category" class="ProductCategory" column="Category"
not-null="false" />

Ayende Rahien

unread,
Jun 25, 2008, 7:39:08 AM6/25/08
to nhu...@googlegroups.com
The moon is not aligned right, please change it to be aligned in 58 degrees to your cpu exact center in relation to the center of the Earth.

GIGO

James Gregory

unread,
Jun 25, 2008, 7:54:42 AM6/25/08
to nhu...@googlegroups.com
Are you able to catch the exception and have a look at the inner-exception?

Niclas Pehrsson

unread,
Jun 25, 2008, 8:07:47 AM6/25/08
to nhusers
No I dont get the exception that causes my application to fail. Its
caught somewhere in NHibernate.dll i guess.

I uses the column Category in my ProductCategory mapping to but if I
comment out that nothing changes anyway. I have like 4 classmappings
with maybe 3 of these kind of mappings with 6 Exceptions like that. I
know its really hard to know why cause of my short error description.
Just wonder what I should look for.

On Jun 25, 1:54 pm, "James Gregory" <jagregory....@gmail.com> wrote:
> Are you able to catch the exception and have a look at the inner-exception?
>
> On Wed, Jun 25, 2008 at 11:56 AM, Niclas Pehrsson <pehrs...@gmail.com>

Ayende Rahien

unread,
Jun 25, 2008, 8:09:38 AM6/25/08
to nhu...@googlegroups.com
Stop at the exception, use VS exception dialog to get the full exception string.

James Gregory

unread,
Jun 25, 2008, 8:16:23 AM6/25/08
to nhu...@googlegroups.com
Attach the debugger, then using the Exceptions dialog you can set the debugger to break when an exception is thrown (not just when one isn't handled). That should let you get to the exception and have a closer look.

Gustavo Ringel

unread,
Jun 25, 2008, 8:21:32 AM6/25/08
to nhu...@googlegroups.com
from the category side you should have a one to many relation to productcategory and from productcategory you have a many-to-one to category.
 
In categories you should have a <bag>, <set> <idbag> or <list> depending on what you're doing and mapping ut as an IList/ISet
 
Gustavo.

Paul Cowan

unread,
Jun 25, 2008, 8:36:18 AM6/25/08
to nhu...@googlegroups.com
I have the same problem with a number of mappnigs,
 
An exception says:

property not found: id on entity ncontinuity2.core.domain.Company
 
My company mapping file is below and does not have an id column or an id property.  I am totally lost but the application seems to work:


<?
xml version="1.0" encoding="utf-8" ?>
<
hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<
class name="ncontinuity2.core.domain.Company,ncontinuity2.core" table="Companies" lazy="true">
<
cache usage="read-write"/>
    <
id name="Uid" column="Uid" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
    <
generator class="guid"/>
</
id>
<
property column="name" type="String" name="Name" length="150" unique="true" not-null="true"/>
<
property column="deleted" type="Boolean" name="Deleted" not-null="true"/>
<
many-to-one name="Country" column="countryuid" class="ncontinuity2.core.domain.Country,ncontinuity2.core" not-found="exception" not-null="true"/>
<
bag name="BusinessUnits" cascade="all-delete-orphan" lazy="true" table="BusinessUnits" inverse="true">
<
cache usage="read-write"/>
<
key column="companyuid"/>
<
one-to-many class="ncontinuity2.core.domain.BusinessUnit,ncontinuity2.core"/>
</
bag>
<
bag name="Contacts" inverse="true" lazy="true" cascade="all">
<
key column="companyuid"/>
<
one-to-many class="ncontinuity2.core.domain.Contact,ncontinuity2.core"/>
</
bag>
<
bag name="Users" inverse="true" lazy="true" cascade="all">
<
cache usage="read-write"/>
<
key column="companyuid"/>
<
one-to-many class="ncontinuity2.core.domain.User,ncontinuity2.core"/>
</
bag>
<
property column="scid" type="Int32" name="OldId" not-null="false"/>
</
class>
</
hibernate-mapping>




dag...@hotmail.com



Date: Wed, 25 Jun 2008 14:21:32 +0200
From: gustavo...@gmail.com
To: nhu...@googlegroups.com
Subject: [nhusers] Re: A first chance exception of type 'NHibernate.MappingException' occurred in NHibernate.dll

Paul Cowan

unread,
Jun 25, 2008, 9:03:00 AM6/25/08
to nhu...@googlegroups.com
Its happening on most of my classes.

It could not be something to do with me calling my identifier Uid?

dag...@hotmail.com


From: dag...@hotmail.com

To: nhu...@googlegroups.com
Subject: [nhusers] Re: A first chance exception of type 'NHibernate.MappingException' occurred in NHibern
Date: Wed, 25 Jun 2008 12:36:18 +0000
</html

Gustavo Ringel

unread,
Jun 25, 2008, 9:53:01 AM6/25/08
to nhu...@googlegroups.com
Do you have in your company class an Uid property?

Gustavo.

Paul Cowan

unread,
Jun 25, 2008, 9:56:01 AM6/25/08
to nhu...@googlegroups.com
I do although it is inherited from a base class.

All objects with a Guid for an identifier inherit from the same base class.

It is only happening with Guids I think

dag...@hotmail.com


Date: Wed, 25 Jun 2008 15:53:01 +0200
<br

Niclas Pehrsson

unread,
Jun 25, 2008, 10:01:19 AM6/25/08
to nhusers
Yes I will attatch it.

My Mappings looks like this.

<class name="ProductCategory">
<id name="Id" access="nosetter.camelcase" type="guid">
<generator class="guid" />
</id>

<property name="Name" type="String" not-null="true" />

<many-to-one name="ParentCategory" class="ProductCategory"
column="ParentCategory" not-null="false" />

<bag name="PersistedCategoryChilds" access="field.camelcase"
inverse="false">
<key column="ParentCategory" />
<one-to-many class="ProductCategory" />
</bag>

<bag name="PersistedProducts" access="field.camelcase"
inverse="false">
<key column="Category" />
<one-to-many class="Product" />
</bag>
</class>

<class name="Product" table="[Product]">
<id name="Id" access="nosetter.camelcase" type="guid">
<generator class="guid" />
</id>

<property name ="ProductId" type="String" length="250" not-
null="true" />
<property name="Name" type="String" length="250" not-null="true" /
>
<property name="Price" type="Decimal" not-null="true" />

<many-to-one name="Category" class="ProductCategory"
column="Category" not-null="false" />

</class>

On Jun 25, 2:21 pm, "Gustavo Ringel" <gustavo.rin...@gmail.com> wrote:
> from the category side you should have a one to many relation to
> productcategory and from productcategory you have a many-to-one to category.
>
> In categories you should have a <bag>, <set> <idbag> or <list> depending on
> what you're doing and mapping ut as an IList/ISet
>
> Gustavo.
>

Gustavo Ringel

unread,
Jun 25, 2008, 10:15:25 AM6/25/08
to nhu...@googlegroups.com
Can you show the base class?

Fabio Maulo

unread,
Jun 25, 2008, 11:02:14 AM6/25/08
to nhu...@googlegroups.com
2008/6/25 Paul Cowan <dag...@hotmail.com>:

I have the same problem with a number of mappnigs,

number of mappings ?!?!?
What mean ?
Who write a lot of mappings at the same time without a little CRUD test for each class ?
Fabio Maulo

P.S. The mapping contain another example of inappropriate unsaved-value usage.

Paul Cowan

unread,
Jun 25, 2008, 10:18:35 AM6/25/08
to nhu...@googlegroups.com
>> Can you show the base class?
 
Certainly:


public
class DBObjectBase : ObjectBase
{
 
    protected Guid _uid;

  


    public virtual Guid Uid { get { return _uid; } set { _uid = value; } }  
     public virtual int OldId { get; set; }
 
     [
ScriptIgnore]
     public virtual DateTime UpdateTimestamp { get; set; }

 


     public override bool IsNew { get { return _uid == Guid.Empty; } }

 
  


     public DBObjectBase()      {
         _uid =
new Guid();
     }

}


dag...@hotmail.com


Date: Wed, 25 Jun 2008 16:15:25 +0200
<br

Paul Cowan

unread,
Jun 25, 2008, 11:11:17 AM6/25/08
to nhu...@googlegroups.com
number of mappings ?!?!?
What mean ?
 
I mean, if I have a number of my persistable classes that are raising the same exception, that same exception is:

property not found: id on entity ncontinuity2.core.domain.DifferentClassname


>>  Who write a lot of mappings at the same time without a little CRUD test for each class ?

Not me, I have unit tests for all my classes so your point is incorrect.

In fact it is only in the output window when I run my tests do I see the exception.  It is not being bubbled up so on the surface it is not stopping me, I just want to know how this exception is

>> P.S. The mapping contain another example of inappropriate unsaved-value usage.

Can  you explain how it is innapropriate.  I think for Guid, my unsaved-value is completelly correct, ie and empty Guid.

Nowhere in my mappings do I have a property named id.

Explain that one or to quote you "What mean ?"
 



dag...@hotmail.com



Date: Wed, 25 Jun 2008 12:02:14 -0300
From: fabio...@gmail.com

To: nhu...@googlegroups.com
Subject: [nhusers] Re: A first chance exception of type 'NHibernate.MappingException' occurred in NHibern

Fabio Maulo

unread,
Jun 25, 2008, 12:31:42 PM6/25/08
to nhu...@googlegroups.com

2008/6/25 Paul Cowan <dag...@hotmail.com>:
I mean, if I have a number of my persistable classes that are raising the same exception, that same exception is:


property not found: id on entity ncontinuity2.core.domain.DifferentClassname

Do you have a class named  "DifferentClassname" ? because apparently the problem is there.


>>  Who write a lot of mappings at the same time without a little CRUD test for each class ?

Not me, I have unit tests for all my classes so your point is incorrect.

In fact it is only in the output window when I run my tests do I see the exception.  It is not being bubbled up so on the surface it is not stopping me, I just want to know how this exception is

What I mean is that when I have an exception in a mapping it can't appear more than one time because I don't write another mapping since I solve the problem; for that I don't understand "same problem with a number of mappings".
 


>> P.S. The mapping contain another example of inappropriate unsaved-value usage.

Can  you explain how it is innapropriate.  I think for Guid, my unsaved-value is completelly correct, ie and empty Guid.

I refer to a previous post in this list.
http://groups.google.com.ar/group/nhusers/browse_thread/thread/ebf624f63306f9e2
Inappropriate mean that unsaved-value, in your case, is unneeded because the value is the same NH use like unsaved-value by default (you can omit it in your mapping).

--
Fabio Maulo

Paul Cowan

unread,
Jun 25, 2008, 12:39:11 PM6/25/08
to nhu...@googlegroups.com
>>Do you have a class named  "DifferentClassname" ? because apparently the problem is there

Are you for real?

You obviously think I am that stupid.
 
The company class I posted was one such example.


>> What I mean is that when I have an exception in a mapping it can't appear more than one time because I don't write another mapping since I solve the problem;

I REPEAT, it is not bubbling the exception, I just noticed it in the output window when I run my tests.  Previously I did not notice it.

Thank you for your condrascending, irratating responses.

The link you sent is irrelevant to my problem.

You have really helped in the respect of annoying me.

If the post annoys you then do not reply with such rude answers.


 

dag...@hotmail.com



Date: Wed, 25 Jun 2008 13:31:42 -0300

From: fabio...@gmail.com
To: nhu...@googlegroups.com
Subject: [nhusers] Re: A first chance exception of type 'NHibernate.MappingException' occurred in NHibern


Gustavo Ringel

unread,
Jun 25, 2008, 3:44:26 PM6/25/08
to nhu...@googlegroups.com
Hi i don't think that nobody is trying to annoy...Fabio points that you don't need this unsaved-value in the id. because NHibernate don't need to have an unused-value if you are using the default of the type.
 
Chances are that Nhibernate gets wrong this 00000000-0... etc, you should test removing this for the mappings and see if the exception disappears or not.
 
I don't think that people who spent a lot of time of their lives contributing or leading development of frameworks that we use extensively use their spare time in the forums only to annoy others...
 
Gustavo.

Will Shaver

unread,
Jun 25, 2008, 3:50:11 PM6/25/08
to nhu...@googlegroups.com
These type of exceptions are always difficult to track down. The moon-alignment comment was probably uncalled for, but I can understand the frustration of trying to help people with not enough information. I highly recommend getting the NH source, and stepping into the error. VS2008 can be configured to do so quite easily: Tools->Options->Debugging->General [Uncheck] Enable Just My Code
 
 -Will

Roger Kratz

unread,
Jun 25, 2008, 5:22:22 PM6/25/08
to nhu...@googlegroups.com

I also get a lot of these MappingException:s thrown at start up. The method that’s causing most of these first chance exceptions (MappingException: “property not found”) for me are AbstractPropertyMapping.HasNonIdentifierPropertyNameId(….) that relies on try/catch making it decision.

 

 Personally I haven’t really cared much about it myself though, even though it’s a bit annoying J

 

/Roger


--
Fabio Maulo
</html

Paul Cowan

unread,
Jun 26, 2008, 4:25:38 AM6/26/08
to nhu...@googlegroups.com
>> I don't think that people who spent a lot of time of their lives contributing or leading development of frameworks that we use extensively use their spare time in the forums only to annoy others...

I totally agree, I owe a big gratitude to the whole NHibernate community.  I am in awe of the code and the concept.

But my point is that, I do not think my post was even read.

In my original post, I get an exception that is not bubbled up that states that it cannot map a property that is not specified in the mapping or the class to the entity.

I am curious to know why.

I have tried removing the unsaved-value and ran my tests that I was ignorantly accused of not writing and get the same result.

Sounds like a bug to me.

If Fabio finds my post below him (as he very much sounded like), then please do not answer.

I am not the first person to post with this problem but the response was rude.



dag...@hotmail.com


Date: Wed, 25 Jun 2008 21:44:26 +0200
From: gustavo...@gmail.com
Fabio Maulo<br

Paul Cowan

unread,
Jun 26, 2008, 4:28:18 AM6/26/08
to nhu...@googlegroups.com
I am still really curious as to why this is being raised.
I am getting it for a property that does not exist in either the mapping or the class.

dag...@hotmail.com



Subject: [nhusers] Re: A first chance exception of type 'NHibernate.MappingException' occurred in NHibern
Date: Wed, 25 Jun 2008 23:22:22 +0200
From: Roger...@teleopti.com
To: nhu...@googlegroups.com

Ayende Rahien

unread,
Jun 26, 2008, 4:54:52 AM6/26/08
to nhu...@googlegroups.com
The problem is with your question. You got an error. That is all well and good, but there is absolutely nothing anyone can do without further information.
I am getting (both here and privately) just too much contacts looking like "NHIBERNATE BUGZ!! URGENT", with the content of "When I use NHbiernate I get an error, assist fast, I need this for tomorrow".

This is getting pretty old, very fast, and has caused the snippy comments.
I apologize for that.

The template for question in the forum is:

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailinglists/HowToAskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

Roger Kratz

unread,
Jun 26, 2008, 5:02:57 AM6/26/08
to nhu...@googlegroups.com

AbstractPropertyMapping.HasNonIdentifierPropertyNameId(….) will check for a _property_ called “id”. When this is not found, an exception is thrown. That’s why you see all these first chance exceptions. Even if your identifier would be called “id” I you will have the same exception thrown/caught.

 

Unfortunately I haven’t had a closer look why this is needed. I have no doubt it’s there for a reason but of course it would be better if it could be handled without relying on catching exceptions.

 

If no one here can give a clear answer why it should be handled this way, please step code and send a patch for it J


</html

Paul Cowan

unread,
Jun 26, 2008, 5:00:14 AM6/26/08
to nhu...@googlegroups.com
Never once did I post or even insinusate that my bug is life threatening or in anyway of the fashion :"NHIBERNATE BUGZ!! URGENT", 

As I have stated now a few times, the bug is not being bubbled up.

It only appears on the output window when I run my tests.

I have set the debugger to break on all exceptions and have witnessed the fact that it is looking for a property named "id" that does not exist on either the mapping or the class.

Other people have noticed this but I received a post stating that I had not written any tests etc.

Even if I had not (which I have), this is irrelevant.

If I am being rude or pedantic, then I apologise.

I just would like to better understand why.

I have pushed my knowledge of the bug as far as I can.



 

dag...@hotmail.com


Date: Thu, 26 Jun 2008 11:54:52 +0300
From: aye...@ayende.com

Ayende Rahien

unread,
Jun 26, 2008, 5:22:37 AM6/26/08
to nhu...@googlegroups.com
inline

On Thu, Jun 26, 2008 at 12:00 PM, Paul Cowan <dag...@hotmail.com> wrote:
Never once did I post or even insinusate that my bug is life threatening or in anyway of the fashion :"NHIBERNATE BUGZ!! URGENT", 

Nor do I think you did. You got the burnt of emptied patience because of them.
 
As I have stated now a few times, the bug is not being bubbled up.

This is not a bug. This is throwing a known exception and handling that.
 
I just would like to better understand why.

Most likely because the practice of using exceptions in this manner is more common in Java.
 


Fabio Maulo

unread,
Jun 26, 2008, 8:38:06 AM6/26/08
to nhu...@googlegroups.com
2008/6/26 Paul Cowan <dag...@hotmail.com>:

If Fabio finds my post below him (as he very much sounded like), then please do not answer.

I am not the first person to post with this problem but the response was rude.


I'm sorry!
The problem with mails is that we can't see our face. You don't know me and I don't know you... I don't considerer you a stupid.
The first response was only for curiosity.

I never see your bug and I don't have a test to help you better.
If you think it is really a bug, try to reproduce it in a test (outside your entire system), send us a test to a new JIRA and we can work on it to help you with your project (free of charge, don't wary about that). 

Bye.
Fabio Maulo

Ken Egozi

unread,
Jun 26, 2008, 8:52:41 AM6/26/08
to nhu...@googlegroups.com
People do not invest their time in OSS because they think that input from the community is below them.
On the contrary - the whole point of putting your code in the open is to get constructive criticism.

On high volume OSS projects, a lot of noise is being generated. Ayende has written here about that a few messages ago. As a commiter on several of these I can tell ya that in the best interest of the users community for OSS projects, is to stick to the *constructive* bit. The less noise we have, the more time we get to fix problems and add new features. Dead simple.

Another point - many times, even if the question is well put, as in any case of remote-problem-fixing (like on any support phone call), the helping people cannot rely on any assumption. So you can't expect a volunteer to try and debug something and help a user for quite some time, just to notice after spending a lot of time that the user didn't do an obvious thing (queried the wrong DB, didn't rebuild, etc.) You should not be offended when asked with these questions. Again, supplying with the most data on your problem might save a few of these questions.
--
Ken Egozi.
http://www.kenegozi.com/blog
http://www.musicglue.com
http://www.castleproject.org
http://www.mamaherb.com
http://www.gotfriends.co.il

Fabio Maulo

unread,
Jun 26, 2008, 9:45:30 AM6/26/08
to nhu...@googlegroups.com
I spent 5 minute to try a basic test without any mapping exception.

    <class name="Company" table="Companies" lazy="true">

        <cache usage="read-write"/>
        <id name="Uid" column="Uid" type="System.Guid" unsaved-value="00000000-0000-0000-0000-000000000000">
            <generator class="guid"/>
        </id>
        <property column="name" type="String" name="Name" length="150" unique="true" not-null="true"/>
        <property column="deleted" type="Boolean" name="Deleted" not-null="true"/>
    </class>

    public class Company
    {
        protected Guid _uid;
        private string name;
        private bool deleted;

        public virtual string Name
        {
            get { return name; }
            set { name = value; }
        }

        public virtual bool Deleted
        {
            get { return deleted; }
            set { deleted = value; }

        }

        public virtual Guid Uid { get { return _uid; } set { _uid = value; } }

    }

Bye.
--
Fabio Maulo

Fabio Maulo

unread,
Jun 26, 2008, 9:48:16 AM6/26/08
to nhu...@googlegroups.com
mmmm..... perhaps Paul are doing something else...

Paul, when you are receiving the exception ?
At run-time after some kind of query ?

Fabio Maulo

Fabio Maulo

unread,
Jun 26, 2008, 10:16:57 AM6/26/08
to nhu...@googlegroups.com
Paul.
When you debug your app, are you debugging NH code too ?

In NH we are using an "internal exception catching" only to check if an entity have or not a property named "id".
The "id" is a special property for HQL and for us know if the entity have or not a property named "id" is a way to apply some short-cut for relationship.

If you don't have a property named "ïd" an exception is trowed and catch internally by NH (your app don't receive the exception).

Is this your case ?

If so the solution is :
Don't include NH in your debug or reference a NHibernate.dll compiled as release (not debug).

Be happy.
Fabio Maulo

Roger Kratz

unread,
Jun 26, 2008, 10:47:47 AM6/26/08
to nhu...@googlegroups.com

<< If you don't have a property named "ïd" an exception is trowed and catch internally by NH (your app don't receive the exception).
Is this your case ?>>

 

I’m sure Paul will reply himself, but I guess this is what his subject said (“a first chance exception”).

 

FYI – the same will happen even if your identifier/property is called id (maybe only if it’s mapped to a field, I don’t know?). There are quite many exceptions being thrown internally (~100 in our app) at start up which may start developers wondering what’s going on.

 

Keep up the great work!

 

From: nhu...@googlegroups.com [mailto:nhu...@googlegroups.com] On Behalf Of Fabio Maulo
Sent: den 26 juni 2008 16:17
To: nhu...@googlegroups.com
Subject: [nhusers] Re: A first chance exception of type 'NHibernate.MappingException' occurred in NHibern

 

Paul.

Fabio Maulo

unread,
Jun 26, 2008, 10:59:17 AM6/26/08
to nhu...@googlegroups.com

2008/6/26 Roger Kratz <Roger...@teleopti.com>:

I'm sure Paul will reply himself, but I guess this is what his subject said ("a first chance exception").

Well.. so I don't understand what mean the subject.... my problem.

 

FYI – the same will happen even if your identifier/property is called id (maybe only if it's mapped to a field, I don't know?).

Yes the special case is with "id" in lower case. We are using it when you have an association using <any>, for example, but the word "id" in HQL mean "the id of your entity".

There are quite many exceptions being thrown internally (~100 in our app) at start up which may start developers wondering what's going on.

Well... for me would be more understandable something like:
"When I debug NH code I saw a catch exception in the method XYZ......."

Well... now we can wait the Paul response and probably close this thread.

Fabio Maulo

Paul Cowan

unread,
Jun 26, 2008, 8:39:46 AM6/26/08
to nhu...@googlegroups.com
>> try to reproduce it in a test (outside your entire system), send us a test to a new JIRA
 
I will certainly take that on board.

Keep up the good work!!

dag...@hotmail.com



Date: Thu, 26 Jun 2008 09:38:06 -0300

From: fabio...@gmail.com
To: nhu...@googlegroups.com
Subject: [nhusers] Re: A first chance exception of type 'NHibernate.MappingException' occurred in NHibern

Paul Cowan

unread,
Jun 26, 2008, 10:13:43 AM6/26/08
to nhu...@googlegroups.com
The exception is not bubbled up.

I only noticed the error when I was running my tests.

It is happening in clas NHibernate.Mapping.PersistentClass
 
It is happening in the GetProperty method, line 293 of the PersistentClass source.

It throws a new mapping exception with the message set to:

property not found: id on entity ncontinuity2.core.domain.Company

The exception is swallowed in the HasNonIdentifierPropertyNamedId method of the AbstractPropertyMapping class.

There is the following TODO: comment on the method


// TODO : would be great to have a Mapping#hasNonIdentifierPropertyNamedId method
// I don't believe that Mapping#getReferencedPropertyType accounts for the identifier property; so
// if it returns for a property named 'id', then we should have a non-id field named id


It is by no means a show stopper, I am just curious as to why it is looking for a property named id.

Thanks for your help.




dag...@hotmail.com



Date: Thu, 26 Jun 2008 10:45:30 -0300

From: fabio...@gmail.com
To: nhu...@googlegroups.com
Subject: [nhusers] Re: A first chance exception of type 'NHibernate.MappingException' occurred in NHibern

Wolli

unread,
Jun 26, 2008, 10:21:17 AM6/26/08
to nhu...@googlegroups.com

Btw (on the danger of teling nothing new …), you can hook on those exceptions in VS 2005. Debug -> Exceptions and then add a new CLR exception “NHibernate.MappingException”. If you have the debug symbols for NHibernate.dll and the source path is correct, it should stop whenever this exeption is thrown.

 

Wolfgang

Hielke Hoeve

unread,
Sep 10, 2008, 8:42:30 AM9/10/08
to Roger Kratz, nhu...@googlegroups.com
First off: Hi and nice to see that NHibernate now has it's own spot on
the Internet! After some effort to compile NHibernate, Spring and
Memcached for our project I have found why our project is giving a lot
of "first chance..." lines in the ouput tab of VS.
I am sorry if this first post comes to you as anything else but
friendly and informative. My only reason for posting here is to
clearify what NHibernate does in this case and ask if this was
actually meant or maybe done unwillingly. I don't see this as a bug
only as something dirty and requiring attention, some day...

> On Jun 26, 11:02 am, "Roger Kratz" <Roger.Kr...@teleopti.com> wrote:
> AbstractPropertyMapping.HasNonIdentifierPropertyNameId(....) will check


> for a _property_ called "id". When this is not found, an exception is
> thrown. That's why you see all these first chance exceptions. Even if
> your identifier would be called "id" I you will have the same exception
> thrown/caught.

This is because the code throwing the exception is a generic property
lookup function PersistantClass:

1 public Property GetProperty(string propertyName)
2 {
3 IEnumerable<Property> iter = PropertyClosureIterator;
4 Property identifierProperty = IdentifierProperty;
5 if (identifierProperty != null &&
identifierProperty.Name.Equals(StringHelper.Root(propertyName)))
6 {
7 return identifierProperty;
8 }
9 else
10 {
11 return GetProperty(propertyName, iter);
12 }
13 }

What strikes me as odd is that when NHibernate has the identifier
property (line 4) and it is not the same as the one defined in some
struct (line 5) it still wants to look in all the normal properties
(so excluding identifier properties) for the column (line 11). In our
case this is never the case, because we do not use access="field" on
our Id properties nor do we name our identifier property "id". This
gives us about 1632 "first chance" lines in the output tab in VS.
Which increases our startup time with about 100%.

This all is called by the following code:

1 protected void InitIdentifierPropertyPaths(string path,
EntityType etype, string[] columns, IMapping factory)
2 {
3 IType idtype =
etype.GetIdentifierOrUniqueKeyType(factory);
4 string idPropName =
etype.GetIdentifierOrUniqueKeyPropertyName(factory);
5 bool hasNonIdentifierPropertyNamedId =
HasNonIdentifierPropertyNamedId(etype, factory);
....

We do have the identifier property name of the Mapping (line 4) but
let's see if the class we map to has a property which is called "id"
but is not an identifier property (line 5). At one hand I can
understand that it wants to look for the property "id" but then either
let us specify our default value for "id" (which is specified in the
struct EntityPersister) in a/some config or don't search for it at
all. Throwing exceptions and not using them (logging or otherwise) is
a bit of a dirty approach. I would make addional functions which
accept another argument, namely the property NHibernate has already
found (line 4) so that NHibernate does not have to throw and uncleanly
catch an exception.

> Unfortunately I haven't had a closer look why this is needed. I have no
> doubt it's there for a reason but of course it would be better if it
> could be handled without relying on catching exceptions.

It would indeed be better. With large applications (with NHibernate
and Spring in our case) the startup time is already a bit long but
because VS logs these unused Exceptions in its output tab the startup
time is doubled if not tripled.
We just moved from NHibernate 1.2 to NHibernate 2.0 and the startup
time has tripled from 20 seconds to nearly 60 seconds.

I hope my post was clear to you, if not don't hesitate to say so.

Greetings,

Hielke Hoeve
Topicus Onderwijs BV, Netherlands

Fabio Maulo

unread,
Sep 10, 2008, 10:28:14 AM9/10/08
to nhu...@googlegroups.com
Hi please create a JIRA for this issue, it is a minor fix and we can fix it soon for NH2.0.1 (or NH2.0.0SP1).
Thanks.
Bye

2008/9/10 Hielke Hoeve <hielke...@gmail.com>



--
Fabio Maulo
Reply all
Reply to author
Forward
0 new messages