I think I may have mapped these wrong but I can't figure out a good way of doing it. I have a many to many relationship of a Vehicle and Inspections. There are multiple Vehicles that each can have different inspections. The problem is I need an expiration date on the associate table so I can figure out when each Vehicle has an expired schedule. I am wondering if there is a better way that to create a separate collectioin and then have to programmatically figure out which inspection goes with a vehicle and then get the LastChecked date.
Vehicle(VehicleID,Make,Model)
Inspection(InspectionID,RegulatoryBody,InspectionName)
Vehicle_Inspection(VehicleID,InspectionID,Lastchecked)
Mapping Files
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="FleetManagement.BusinessLayer.Inspection, FleetManagement.BusinessLayer" table="RegulatoryInspection">
<id name="InspectionID" column="InspectionID" type ="String" length="50">
<generator class="assigned" />
</id>
<property name="RegulatoryBody" />
<property name="NameOfInspection" />
<property name="TypeOfSchedule" />
<property name="Period" />
<set name="Vehicles" lazy="true" cascade="none" table="Vehicle_Schedule">
<key column="InspectionID" />
<many-to-many class="FleetManagement.BusinessLayer.Vehicle, FleetManagement.BusinessLayer"
column="VehicleID" outer-join="auto" />
</set>
<bag name="Vehicle_Schedules" table="Vehicle_Schedule" lazy ="false" cascade="save-update">
<key column="InspectionID" />
<one-to-many class="FleetManagement.BusinessLayer.Vehicle_Schedule, FleetManagement.BusinessLayer" />
</bag>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="FleetManagement.BusinessLayer.Vehicle, FleetManagement.BusinessLayer" table="Vehicle">
<id name="VehicleID" column="VehicleID" type="String" length="50">
<generator class="assigned" />
</id>
<!--Mapp properties I'd like to be persist/fetch
Assume colum = property name-->
<property name="UnitID" />
<property name="Body_Type" />
<property name="Make" />
<property name="Model" />
<property name="Year" />
<property name="FunctionCode" />
<property name="EnterpriseNO" />
<property name="VIN" />
<property name="Plate" />
<property name="Location" />
<property name="DriverName" />
<property name="Description" />
<bag name="Inspection" table="Vehicle_Inspections" lazy="false" cascade="save-update" >
<key column="VehicleID" />
<many-to-many class="FleetManagement.BusinessLayer.Inspection, FleetManagement.BusinessLayer"
column="InspectionID" outer-join="auto" />
</bag>
<bag name="Vehicle_Inspection" table="Vehicle_Inspection" lazy ="false" cascade="save-update">
<key column="VehicleID" />
<one-to-many class="FleetManagement.BusinessLayer.Vehicle_Inspections, FleetManagement.BusinessLayer" />
</bag>
Code:
<class name="FleetManagement.BusinessLayer.Vehicle_Inspection, FleetManagement.BusinessLayer" table="Vehicle_Inspection">
<composite-id name="VehicleInspectionID" class="FleetManagement.BusinessLayer.IVehicleinspectionID, FleetManagement.BusinessLayer">
<key-property name="VehicleID" />
<key-property name="InspectionID" />
</composite-id>
<property name="LastChecked" />
<property name="NextCheckDate" />
</class>