NH 3.1 hbm mapping changes?

54 views
Skip to first unread message

Dwarrel

unread,
Jun 15, 2011, 8:45:11 AM6/15/11
to nhusers
Have been running an application under .Net 2.0 with NH 2.1 for a year
now and that worked without problems. After upgrading this to .Net 4.0
I only needed to address the ISet issue but for the rest it compiles
and runs great (still using NH 2.1)

However when I changed the same code to NH 3.1 suddenly I get compile
errors about my hbm.xml mapping files. Is anyone aware of changes that
need to be applied to these files? Would have expected issues
between .Net versions but not with the change to NH 3.1.

The first file it complains about is this crew mapping file, which it
crashes on with an "Ambiguous Match Exception" during the init of the
session factory. Anyone having seen this before? Am wondering about
the "field.pascalcase-m-underscore" mapping but again it works all
fine with NH 2.1

<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping auto-import="true"
default-lazy="true"
assembly="MAF.DB"
namespace="MAF.DB.BusinessObject"
default-access="field.pascalcase-m-underscore"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xmlns="urn:nhibernate-mapping-2.2">
<class name="Crew" dynamic-update="true">
<id name="CrewID">
<generator class="MAF.DB.Access.PKGenerator, MAF.DB" />
</id>
<version name="Version" access="field" type="Byte"/> <!--
enables optimistic locking -->
<set name="CrewChecks" inverse="true" cascade="all-delete-
orphan">
<key column="CrewID"/>
<one-to-many class="CrewCheck"/>
</set>
<property name="DisplayName"/>
<many-to-one name="Homebase"
class="Airstrip"
column="HomebaseID"/>
<many-to-one name="Nationality"
class="Country"
column="NationalityID"/>
<many-to-one name="ProgrammeCountry"
class="Country"
column="ProgrammeCountryID"/>
<property name="Name"/>
<property name="PassportNumber"/>
<property name="Weight"
type="MAF.DB.BusinessObject.WeightUserType, MAF.DB"/>
<property name="Active"/>
<property name="Comments"/>
<property name="EmailAddress"/>
<property name="DisplayColour"/>
<property name="CStripRated"/>
<property name="LimitationType"/>
<many-to-one name="ACTypeLimitation"
class="AircraftType"
column="ACTypeLimitationID"/>
<property name="FlightTime1DayLimit"/>
<property name="FlightTime7DayLimit"/>
<property name="FlightTime28DayLimit"/>
<property name="FlightTime90DayLimit"/>
<property name="FlightDutyTime1DayLimit"/>
<property name="FlightDutyTime7DayLimit"/>
<property name="FlightDutyTime14DayLimit"/>
<property name="FlightDutyTime28DayLimit"/>
<property name="FlightDutyTime90DayLimit"/>
<property name="TotalDutyTime1DayLimit"/>
<property name="TotalDutyTime7DayLimit"/>
<property name="TotalDutyTime14DayLimit"/>
<property name="TotalDutyTime28DayLimit"/>
<property name="LastLandingTime"
type="MAF.DB.BusinessObject.TimeSpanUserType, MAF.DB"/>
<property name="FuelReserve"/>
<property name="LastModified"/>
<property name="LastModifiedBy"/>
</class>
<sql-query name="IsCrewAvailable">
<query-param name="CrewID" type="String"/>
<query-param name="StartPeriod" type="Date"/>
<query-param name="EndPeriod" type="Date"/>
<query-param name="IgnoreFlightID" type="String"/>
<return-scalar column="Reason" type="String"/>
<![CDATA[EXEC IsAvailable
NULL, :CrewID, :IgnoreFlightID, :StartPeriod, :EndPeriod]]>
</sql-query>
<sql-query name="CrewLastLandedAt">
<query-param name="CrewID" type="String"/>
<query-param name="BeforeDate" type="Date"/>
<return-scalar column="AirstripID" type="String"/>
<![CDATA[EXEC LastLandedAt NULL, :CrewID, :BeforeDate]]>
</sql-query>
</hibernate-mapping>

Dwarrel

unread,
Jun 16, 2011, 7:33:23 AM6/16/11
to nhusers
Additional information, when changing to NH 3.0 then the same problem
does NOT occur (only changed the NH binaries, nothing else). Anyone
have any idea where I should be looking to get this resolved? So
project runs fine under .Net 3.5/4.0 with NH 2.1 and NH 3.0 but fails
compiling the hbm mapping files when moving to NH 3.1

CassioT

unread,
Jun 18, 2011, 12:45:03 PM6/18/11
to nhusers
I had problems with the 3.2 version.

The access="field" and access="nosetter.camelcase" options, were
raising am exception (don't remember the type) because I didn't have a
public or protected set defined in my property.

But it's ok on version 3.1

Fabio Maulo

unread,
Jun 18, 2011, 7:01:28 PM6/18/11
to nhu...@googlegroups.com
access="field"  is for fiels
anything else is for properties and the property must exists.

CassioT

unread,
Jun 19, 2011, 1:07:48 AM6/19/11
to nhusers
Hi Fabio,

I use these options exactly for that, and they always worked. I'm not
saying that is a bug. Even knowing that the same configuration worked
on previous releases, I didn't test it too much because I was out of
time. Perhaps is only my mistake.

I just went back to 3.1 and I decided to test it again on 3.2 final
release.

Thanks

Fabio Maulo

unread,
Jun 19, 2011, 10:35:45 AM6/19/11
to nhu...@googlegroups.com
Just remember that when you use field.camelcase or any other similar mapping the property must exists.

CassioT

unread,
Jun 20, 2011, 4:55:55 PM6/20/11
to nhusers
The property exists but in these cases it doesn't has a set or is a
private set.

Thanks

Dwarrel

unread,
Jun 21, 2011, 12:24:20 AM6/21/11
to nhusers
Thanks Fabio, but ehm it does not quite answer my question of changes
in mapping interpreteation between NH 3.0 and 3.1 are there any that
could explain the error? So far I just get a crash when initializing
the session factory which does not quite tell me what is going wrong.
The project used to run under .Net 2.0 with NH 2.1 but changing it to
NET 3.5/4.0 only works when I do not upgrade beyond NH 3.0 it seems.
This is a bit of a shame for all the hard work you guys put in the new
release.

Fabio Maulo

unread,
Jun 21, 2011, 8:24:59 AM6/21/11
to nhu...@googlegroups.com
1) The property have to exists.
2) private setters may cause serious problem with lazy-properties for that reason we have improved the dyn-proxy validation.

If you want you can turn-off the proxy validation through NH's configuration and continue using private setters, but if you do so you have to take care to avoid the usage of lazy-properties (a simple property as lazy)/lazyness relations (a relation with lazy=no-proxy)

CassioT

unread,
Jun 24, 2011, 9:50:38 AM6/24/11
to nhusers
Nice tip about private setters and lazy properties. I believe the same
is valid on properties that don't have a setter.

Thanks.

Shatl

unread,
Jun 25, 2011, 3:57:01 AM6/25/11
to nhu...@googlegroups.com
Hi Fabio,
just to be clear, do you mean only "private", not "protected / internal protected" settrs?

Nexus

unread,
Jun 29, 2011, 10:27:31 AM6/29/11
to nhusers
Shatl,

Yes, he means private setters only, private setters are not
interceptable as i know off
Reply all
Reply to author
Forward
0 new messages