开发者

NHibernate setting access="field.camelcase-underscore" fails in version 3

I have a solution that was created with NHib 1.2 which we're upgrading to NHib 3.0.

Our hbm file has the following property:

<property name="ContentId" column="ContentId" access="field.camelcase-underscore" />

The class doesn't have a ContentId property. This was working fine in NHib 1.2 but now we're getting getting the following exception:

Could not compile the mapping document: XXXX.Core.Domain.Video.hbm.xml ---> NHibernate.MappingException: Problem trying to set property type by reflection ---> NHibernate.MappingException: class Core.Domain.Video, Core, Version=1.0.0.29283, Culture=neutral, PublicKeyToken=null not found while looking for property: ContentId ---> NHibernate.PropertyNotFoundException: Could not find the property 'Content开发者_运维知识库Id', associated to the field '_contentId', in class 'Core.Domain.Video'.

Why would this stop working? Is it still supported in NHib 3?

We have many many properties like this that we might need to add.


NHibernate greatly improved its error messaging and diagnostics in NH2.X and again in NH3.X. You are telling NHibernate that you have a property and you want to map it via field access to a field named by _camelCase convention. You don't have a property named ContentId and NHibernate is letting you know that you lied to it. :)

Try updating your mapping to:

<property name="_contentId" column="ContentId" access="field" />

You will need to update any HQL or Criteria queries to use _contentId rather than ContentId. Another option would be to add a private ContentId property.


I'd like to provide information which helped me answer this question:

http://groups.google.com/group/nhusers/browse_thread/thread/e078734a221c3c0c/ec8b873b385d4426?lnk=gst&q=field+camelcase+underscore#ec8b873b385d4426

In this link Fabio explains the same problem you are having like this:

This mapping

<property name="PositiveValue" access="field.camelcase-underscore" />

mean: For my property named "PositiveValue" you (NH) have to access to the field; to discover which is the associated field you (NH) have to use the strategy "camelcase-underscore".

If there is no property you can't use the accessor with a specific strategy.

Which struck me as a little odd because it meant adding dummy, unused properties, just to make the nhibernate3 compiler happy. The underlying functionality is the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜