views:

204

answers:

2

Hello, and first off thanks for your time to look at this.

For a research project I'm working on, I have a somewhat complex design (which I've been given) to persist to a database via NHibernate.

Here's an example of the class hierarchy:

alt text

TransitStrategy, TransportationCompany and TransportationLocation are all abstract classes.

The XML configuration I have is presently:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="Vacationizer"
               namespace="Vacationizer.Domain.Transit">

<class name="TransitStrategy">

    <id name="TransitStrategyId">
        <generator class="guid" />
    </id>

    <property name="Restrictions" />

    <joined-subclass name="Flight" table="Flight_TransitStrategy">

        <key column="TransitStrategyId" />

        <property name="DepartingAirport" />
        <property name="ArrivingAirport" />
        <property name="Airline" />
        <property name="FlightNumber" />
        <property name="FlightArrivalTime" />
        <property name="FlightDepartureTime" />

    </joined-subclass>

    <joined-subclass name="RentalCar" table="RentalCar_TransitStrategy">

        <key column="TransitStrategyId" />

        <property name="RentalCarBranch" />
        <property name="CarMake" />
        <property name="CarModel" />
        <property name="CarYear" />
        <property name="CarColor" />
        <property name="RentalBegins" />
        <property name="RentalEnds" />

    </joined-subclass>

</class>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="Vacationizer"
               namespace="Vacationizer.Domain.Transit">

<class name="TransportationCompany">

    <id name="TransportationCompanyId">
        <generator class="guid" />
    </id>

    <property name="Name" />
    <property name="Reviews" />
    <property name="Website" />
    <property name="Photo" />

    <joined-subclass name="Airline" table="Airline_TransportationCompany">

        <key column="TransportationLocationId" />

    </joined-subclass>

    <joined-subclass name="RentalCarAgency" table="RentalCarAgency_TransportationCompany">

        <key column="TransportationLocationId" />

    </joined-subclass>

</class>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
               assembly="Vacationizer"
               namespace="Vacationizer.Domain.Transit">

<class name="TransportationLocation">

    <id name="TransportationLocationId">
        <generator class="guid" />
    </id>

    <property name="Name" />
    <property name="Image" />
    <property name="Geolocation" />
    <property name="Reviews" />
    <!-- <property name="HoursOpen" />-->
    <property name="PhoneNumber" />
    <property name="FaxNumber" />

    <joined-subclass name="Airport" table="Airport_TransportationLocation">

        <key column="TransportationLocationId" />

        <property name="AirportCode" />
        <property name="Website" />

    </joined-subclass>

    <joined-subclass name="RentalCarBranch" table="RentalCarBranch_TransportationLocation">

        <key column="TransitStrategyId" />

        <property name="Agency" />

    </joined-subclass>

</class>

However, whenever I try to use this schema I get this error/stack trace:

------ Test started: Assembly: Vacationizer.Tests.dll ------

TestCase 'M:Vacationizer.Tests.VacationRepository_Fixture.TestFixtureSetUp'
failed: Could not compile the mapping document:      Vacationizer.Mappings.TransitStrategy.hbm.xml
    NHibernate.MappingException: Could not compile the mapping document: Vacationizer.Mappings.TransitStrategy.hbm.xml ---> NHibernate.MappingException: Problem trying to set property type by reflection ---> NHibernate.MappingException: class Vacationizer.Domain.Transit.RentalCar, Vacationizer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null not found while looking for property: RentalCarBranch ---> NHibernate.PropertyNotFoundException: Could not find a getter for property 'RentalCarBranch' in class 'Vacationizer.Domain.Transit.RentalCar'
    at NHibernate.Properties.BasicPropertyAccessor.GetGetter(Type type, String propertyName)
    at NHibernate.Util.ReflectHelper.ReflectedPropertyClass(String className, String name, String accessorName)
       --- End of inner exception stack trace ---
    at NHibernate.Util.ReflectHelper.ReflectedPropertyClass(String className, String name, String accessorName)
    at NHibernate.Mapping.SimpleValue.SetTypeUsingReflection(String className, String propertyName, String accesorName)
       --- End of inner exception stack trace ---
    at NHibernate.Mapping.SimpleValue.SetTypeUsingReflection(String className, String propertyName, String accesorName)
    at NHibernate.Cfg.XmlHbmBinding.ClassBinder.CreateProperty(IValue value, String propertyName, String className, XmlNode subnode, IDictionary`2 inheritedMetas)
    at NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary`2 inheritedMetas, UniqueKey uniqueKey, Boolean mutable, Boolean nullable, Boolean naturalId)
    at NHibernate.Cfg.XmlHbmBinding.JoinedSubclassBinder.HandleJoinedSubclass(PersistentClass model, XmlNode subnode, IDictionary`2 inheritedMetas)
    at NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary`2 inheritedMetas, UniqueKey uniqueKey, Boolean mutable, Boolean nullable, Boolean naturalId)
    at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node, HbmClass classSchema, IDictionary`2 inheritedMetas)
    at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode parentNode, IDictionary`2 inheritedMetas)
    at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node)
    at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
       --- End of inner exception stack trace ---
    at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
    at NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc)
    at NHibernate.Cfg.Configuration.ProcessMappingsQueue()
    at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document)
    at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name)
    at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
    at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
    at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
    at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
    at NHibernate.Cfg.Configuration.DoConfigure(IHibernateConfiguration hc)
    at NHibernate.Cfg.Configuration.Configure()
    VacationRepository_Fixture.cs(24,0): at Vacationizer.Tests.VacationRepository_Fixture.TestFixtureSetUp()

0 passed, 1 failed, 0 skipped, took 8.38 seconds (Ad hoc).

Any ideas on how I can implement this differently? Thanks very much!

A: 

From what I see in the exception, it's saying that your RentalCar class does not declare a RentalCarBranch property.

Is that the case?

Neil Moss
Niel, Please see the above comment I made to Diego. Thanks very much though!
Chris Cowdery-Corvan
+1  A: 

The error itself is clear: mapping for RentalCar defines a RentalCarBranch property, that might not be declared (check for typos; personally I'd name the property Branch instead).

There's another error there: you are defining everything as <property>, when all persistent entity references should be declared as <many-to-one>.

Diego Mijelshon
Diego,Thanks so much for your input, but that's a fault on my part in copying over the question. You're *absolutely* right in that your solution would fix it, but another problem I believe was at play.As of 7 AM, I just got it to work, but there were quite a few more complications that got in the way. I'll be posting on my fix later if it passes my unit test suite.Thanks again for your help!
Chris Cowdery-Corvan