Im struggling with the following scenario (not sure if this is even
supported)... currently using NHv3:

Schema:
Manager  manages many Groups
    Manager .---< ManagerGroups {managerId, groupId} >--. Groups
Users or Vehicles (X) belong to one or more groups
    Groups {groupId, type} .---< XGroups {groupId, xId} >---.
User(Group.type:0) or Vehicle(Group.type:1)

The "Groups .--< XGroups >--. User/Vehicle" uses a discriminator based
off of the "Groups" table (column named type{int: 0,1}) to determine
if its a user or vehicle. I have implemented this as a subclass (HBM
follows) as DriverGroup : GroupBase, and VehicleGroup : GroupBase.

The issue is that when I reference the DriverGroup or VehicleGroup
from Manager (as an ISet) NH is not qualifying the query with the
discriminator so I get a "type not of expected type DriverGroup (where
type was VehicleGroup)". If I change the property and map to use
GroupBase it will work but I need to be able to get only that type
(Vehicles OR Drivers) Im concerned with.

So, main question is if this is possible and what I may be doing
wrong, or need to rethink.

Further knowledge I am interested in is being able to do stuff like:
1) Get/FindPaged all drivers/vehicles managed by manager, 2) Get/
FindPaged Transmissions where driver assigned is in group managed by
manager (would be best if NH could construct sub-selects etc so
thousands of records dont have to be returned in order to locate items
qualifying for 20 records of Page X) ... but this may need to be a
separate post.


Here is the HBM for the 'GroupsBase'... Ill post the other mappings if
requested:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-
access="property" auto-import="true" default-cascade="none" default-
lazy="true">
  <class xmlns="urn:nhibernate-mapping-2.2" discriminator-value="0"
mutable="true" name="xyz.NH.Entities.GroupBase, xyz.NH,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="Groups">
    <id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="groupId" />
      <generator class="identity" />
    </id>
    <discriminator type="Int16" force="true">
      <column name="type" />
    </discriminator>
    <property name="GroupName" type="System.String, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="name" />
    </property>
    <property name="Type" type="System.Int32, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <column name="type" />
    </property>
    <set cascade="all" inverse="true" name="Managers"
table="ManagerGroups" mutable="true">
      <key>
        <column name="groupId" />
      </key>
      <many-to-many class="xyz.NH.Entities.Manager, xyz.NH,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
        <column name="managerId" />
      </many-to-many>
    </set>
    <subclass name="xyz.NH.Entities.DriverGroup, xyz.NH,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" discriminator-
value="0">
      <set cascade="all" inverse="true" name="Drivers" table="XGroups"
mutable="true">
        <key>
          <column name="groupId" />
        </key>
        <many-to-many class="xyz.NH.Entities.Driver, xyz.NH,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" not-
found="ignore">
          <column name="ID" />
        </many-to-many>
      </set>
    </subclass>
    <subclass name="xyz.NH.Entities.VehicleGroup, xyz.NH,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" discriminator-
value="1">
      <set cascade="all" inverse="true" name="Vehicles"
table="XGroups" mutable="true">
        <key>
          <column name="groupId" />
        </key>
        <many-to-many class="xyz.NH.Entities.Vehicle, xyz.NH,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" not-
found="ignore">
          <column name="ID" />
        </many-to-many>
      </set>
    </subclass>
  </class>
</hibernate-mapping>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to