-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Many-to-Many with Additional Fields and Subclasses
PostPosted: Thu Jun 08, 2006 12:15 am 
Newbie

Joined: Fri May 05, 2006 12:09 am
Posts: 11
Still a newbie to the design so I may have done this wrong.
I have a many-to-many join that also has additional fields that I need to handle. The vehicles is the main object and then I have schedules, each of the vehicles has different schedules and each schedule can belong to each of the vehicles. Vehicle has a number of more specific types of sub-vehicles that their own properties and methods.


Vehicle
vehicleID
Make
Model

Truck
vehicleID
weight

Schedule
ScheduleID
name


Vehicle_Schedule
vehicleID
scheduleID
LastChecked



I was able to get the Vehicle_Schedule to map correctly as a composite-id so I could get access to the Last checked field. I added the collection to the vehicle class. But I keep getting errors that I need to add a setter on each of my sub-vehicle classes. Is this right, do I have to add Vehicle_Schedule collection to the sub-class? Or have I done something wrong? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 1:59 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
you don't have to add a setter but you do have to add access="nosetter.camelcase" to the mapping file. can you post your mapping files and i'll give it a looksee?

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 8:54 am 
Newbie

Joined: Fri May 05, 2006 12:09 am
Posts: 11
Here are my mapping files

Vehicle
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" />
   
    <set name="Schedules" table="Vehicle_Schedule" lazy="false" cascade="save-update" >
      <key column="VehicleID" />
      <many-to-many class="FleetManagement.BusinessLayer.Schedule, FleetManagement.BusinessLayer"
                     column="InspectionID" outer-join="auto" />
     
    </set>
   
    <set name="Vehicle_Schedule" table="Vehicle_Schedule" lazy ="false" cascade="save-update" inverse ="true" >
      <key column="VehicleID" />

      <one-to-many class="FleetManagement.BusinessLayer.Vehicle_Schedule, FleetManagement.BusinessLayer" />
     
    </set>
   
    <set name="Mileages" table="FuelMileage" lazy="true" cascade="save-update" >
      <key column="MileageID" />
      <one-to-many class="FleetManagement.BusinessLayer.Mileage, FleetManagement.BusinessLayer" />
    </set>
   
    <!--Map the inherited Class Truck-->
    <joined-subclass name="FleetManagement.BusinessLayer.Truck, FleetManagement.BusinessLayer" table="Truck">
      <key column="TruckID" foreign-key="FK_VehicleID" />
      <property name="TireSize" />
      <property name="Weight" column="GrossWeight"/>

      <!--Join the SubClass Pickup-->
      <joined-subclass name="FleetManagement.BusinessLayer.Pickup, FleetManagement.BusinessLayer" table="PickUp">
        <key column="PickUpID" foreign-key="FK_TruckID" />
        <property name="IsDOT" />
      </joined-subclass>

   
    </joined-subclass>

    <joined-subclass name="FleetManagement.BusinessLayer.Forklift, FleetManagement.BusinessLayer" check="Forklift">
      <key column="ForkliftID" foreign-key="fk_VehicleID" />
      <property name="Category" />
      <property name="Manufacturer" />
    </joined-subclass>


  </class>
 
 
</hibernate-mapping>



Vehicle_Schedule
Code:
<?xml version="1.0" encoding="utf-8" ?>


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">

  <class name="FleetManagement.BusinessLayer.Vehicle_Schedule, FleetManagement.BusinessLayer" table="Vehicle_Schedule">

    <composite-id>
      <key-many-to-one name="Vehicle" class="FleetManagement.BusinessLayer.Vehicle, FleetManagement.BusinessLayer" column="VehicleID" />
      <key-many-to-one name="Schedule" class="FleetManagement.BusinessLayer.Schedule, FleetManagement.BusinessLayer" column="InspectionID" />
    </composite-id>

    <property name="LastChecked" />
   
   
  </class>
 
</hibernate-mapping>
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 11:05 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
shoot, i need the class files too. sorry about that...

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 12:13 pm 
Newbie

Joined: Fri May 05, 2006 12:09 am
Posts: 11
Okay. This is kind of where I am wondering if I have gotten lost and have may have a problem.

Code:

Public Class Vehicle
       implements IVehicle

        Public Property VehicleID() As String _
                    Implements IVehicle.VehicleID
            Get
                Return _vehicleID
            End Get
            Set(ByVal value As String)
                _vehicleID = value
            End Set
        End Property

        Public Property UnitID() As Integer _
                Implements IVehicle.UnitID
            Get
                Return _unitId
            End Get
            Set(ByVal value As Integer)
                _unitId = value
            End Set
        End Property

        Public Property Body_Type() As String _
                Implements IVehicle.Body_Type
            Get
                Return _bodyType
            End Get
            Set(ByVal value As String)
                _bodyType = value
            End Set
        End Property

        Public Property Make() As String _
                Implements IVehicle.Make
            Get
                Return _make
            End Get
            Set(ByVal value As String)
                _make = value
            End Set
        End Property

        Public Property Model() As String _
                Implements IVehicle.Model
            Get
                Return _model
            End Get
            Set(ByVal value As String)
                _model = value
            End Set
        End Property

        Public Property Year() As String _
                Implements IVehicle.Year
            Get
                Return _year
            End Get
            Set(ByVal value As String)
                _year = value
            End Set
        End Property

        Public Property Schedules() As Iesi.Collections.ISet _
                Implements IVehicle.Schedules
            Get

                Return Me._schedules

            End Get
            Set(ByVal value As Iesi.Collections.ISet)
                _schedules = value
            End Set
        End Property

        Public Property Vehicle_Schedules() As Iesi.Collections.ISet _
                Implements IVehicle.Vehicle_Schedules
            Get
                Return _vehicle_schedules
            End Get
            Set(ByVal value As Iesi.Collections.ISet)
                _vehicle_schedules = value
            End Set
        End Property

        Public Property Mileages() As Iesi.Collections.ISet _
                    Implements IVehicle.Mileages
            Get
                  Return Me._mileages
            End Get
            Set(ByVal value As Iesi.Collections.ISet)
                _mileages = value
            End Set
        End Property

        Public Property Saving() As Boolean _
                Implements IVehicle.Saving
            Get
                Return _saving
            End Get
            Set(ByVal value As Boolean)
                _saving = value
            End Set
        End Property

        Public Property IsSaved() As Boolean _
                Implements IVehicle.IsSaved
            Get
                Return _isSaved
            End Get
            Set(ByVal value As Boolean)
                _isSaved = value
            End Set
        End Property
End Class

Public Class Vehicle_Schedule

       Public Property VehicleID() As String
            Get
                Return _vehicleID
            End Get
            Set(ByVal value As String)
                _vehicleID = value
            End Set
        End Property

        Public Property ScheduleID() As String
            Get
                Return _scheduleID
            End Get
            Set(ByVal value As String)
                _scheduleID = value
            End Set
        End Property

        Public Property LastChecked() As Date
            Get
                Return _lastChecked
            End Get
            Set(ByVal value As Date)
                _lastChecked = value
            End Set
        End Property

        Public Property Vehicle() As Iesi.Collections.ISet
            Get
                Return _vehicles
            End Get
            Set(ByVal value As Iesi.Collections.ISet)
                _vehicles = value
            End Set
        End Property

        Public Property Schedule() As Iesi.Collections.ISet
            Get
                Return _schedules
            End Get
            Set(ByVal value As Iesi.Collections.ISet)
                _schedules = value
            End Set
        End Property

        Public Overloads Function Equals(ByVal obj As Object) As Boolean

            Return MyBase.Equals(obj)


        End Function

        Public Overloads Function GetHashCode() As Integer

            Return MyBase.GetHashCode()

        End Function
End Class

Public Class Truck
        Public Property TruckID() As String _
                Implements ITruck.TruckID
            Get
                Return _truckID
            End Get
            Set(ByVal value As String)
                _truckID = value
            End Set
        End Property

        Public Property TireSize() As Double _
            Implements ITruck.TireSize
            Get
                Return _tireSize
            End Get
            Set(ByVal value As Double)
                _tireSize = value
            End Set
        End Property

        Public Property Weight() As Integer _
            Implements ITruck.Weight
            Get
                Return _weight
            End Get
            Set(ByVal value As Integer)
                _weight = value
            End Set
        End Property
End Class

    Public Class Schedule
        Implements ISchedule

       Public Property ScheduleID() As String Implements ISchedule.ScheduleID
            Get
                'Return _InspectionID
                Return _scheduleID
            End Get
            Set(ByVal value As String)
                _scheduleID = value
            End Set
        End Property

        Public Property RegulatoryBody() As String Implements ISchedule.RegulatoryBody
            Get
                Return _regulatoryBody
            End Get
            Set(ByVal value As String)
                _regulatoryBody = value
            End Set
        End Property

        Public Property NameOfInspection() As String Implements ISchedule.NameOfInspection
            Get
                Return _nameOfInspection
            End Get
            Set(ByVal value As String)
                _nameOfInspection = value
            End Set
        End Property

        Public Property TypeOfSchedule() As String Implements ISchedule.TypeOfSchedule
            Get
                Return _typeOfSchedule
            End Get
            Set(ByVal value As String)
                _typeOfSchedule = value
            End Set
        End Property

        Public Property Period() As Integer Implements ISchedule.Period
            Get
                Return _period
            End Get
            Set(ByVal value As Integer)
                _period = value
            End Set
        End Property

        Public Property IsSaved() As Boolean Implements ISchedule.IsSaved
            Get
                Return _isSaved
            End Get
            Set(ByVal value As Boolean)
                _isSaved = value
            End Set
        End Property

        Public Property Vehicles() As Iesi.Collections.ISet Implements ISchedule.Vehicles
            Get
                Return _vehicles
            End Get
            Set(ByVal value As Iesi.Collections.ISet)
                _vehicles = value
            End Set
        End Property
#End Region

    End Class


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 12:15 pm 
Newbie

Joined: Fri May 05, 2006 12:09 am
Posts: 11
Also forgot to paste in the constructor but I do have a

Public Sub New()

on each of these classes.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 08, 2006 5:02 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
well you have this mapping:

Code:
<set name="Schedules" table="Vehicle_Schedule" lazy="false" cascade="save-update" >
    <key column="VehicleID" />
    <many-to-many class="FleetManagement.BusinessLayer.Schedule, FleetManagement.BusinessLayer" column="InspectionID" outer-join="auto" />
</set>
   
<set name="Vehicle_Schedule" table="Vehicle_Schedule" lazy ="false" cascade="save-update" inverse ="true" >
    <key column="VehicleID" />

    <one-to-many class="FleetManagement.BusinessLayer.Vehicle_Schedule, FleetManagement.BusinessLayer" />
</set>


pointing two different object models to the same table and that just seems funny to me. i think i see what you are trying to do, but i just don't know the consequences of mapping the entity Schedule to the same Table as VehicleSchedule and cascading the save-updates to both collections. this might be a question for someone more skilled than i in this type of mapping.

-devon


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.