Series of abstract classes and NHibernate
Posted
by Chris Cowdery-Corvan
on Stack Overflow
See other posts from Stack Overflow
or by Chris Cowdery-Corvan
Published on 2010-05-08T20:57:24Z
Indexed on
2010/05/08
21:48 UTC
Read the original article
Hit count: 1024
nhibernate
|hibernate
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:
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!
© Stack Overflow or respective owner