> I was talking about an <idbag />  like this
>  <idbag name="Employees" access="field.camelcase-underscore"
> table="[dbo].[Orders]" cascade="all-delete-orphan" fetch="select">
> <collection-id column="OrderId" type="long"> <generator class="identity"/>
> </collection-id>
>         <key>
> <column name="CustomerID"/>
>         </key>
>         <many-to-many class="Employee">
> <column name="EmployeeID"/>
>         </many-to-many>
>  </idbag>
> 
> where you can specify the collection id. What is the problem with this
> mapping?

        I hadn't looked at id-bag. When I change it, it indeed works. There
is a downside to this though: if the intermediate entity has a compound PK,
it won't work. Admitted that's an edge case, but it's still odd. What's more
odd is that the .xsd suggests that <collection-id> accepts child <column>
elements, however it also requires a column + type (why?) attributes,
suggesting that <column> child elements are not really part of the 'key'. 

        The whole thing feels inconsistent: <key> inside <set> suggests that
the PK is defined with that, so that's re-defining the pk, which is bad (it
creates this problem), however <collection-id> in <idbag> re-defines the PK
of the intermediate entity again as well, while it's already defined in the
intermediate entity's mapping itself. 

        Better would have been IMHO either:
1) I can specify the m:1 (or 1:n) relationships the m:n is defined over. So
Customer 1:n Order and Order m:1 Employee. Which would make (for
Customer.Employees)
<set>
        <property name="Orders">
        <many-to-many>
        <!-- same, or one could think of changing this too to
order.Employee:
                <property name="Employee"/>
        -->
        </many-to-many>
</set>

because 'Customer.Orders' already defines the 1:n relationship from customer
to Order, half of the m:n relationship. 

or 2)
<set>
        <fkey>
                <column name="CustomerID"/>
        </fkey>
        <many-to-many>
        <!-- same as it is now-->
        </many-to-many>
</set>

which would not re-define a pk, but simply would tell NH what the FK field
is of the first relationship. This will likely miss information, if there's
no m:1 defined in the intermediate entity back to in this case 'Customer',
so option 2) is actually pretty bad too. 

As all the information for a m:n is already in the mappings elsewhere, it
simply needs to refer to these elements to tell NH what elements (m:1/1:n
relationships) it has to use to build the query at runtime, that's about it.
As the set is read-only anyway. 

Anyway, as idbag is limited to a single column for the intermediate pk, I'll
add a validation to weed these relationships out of the model before mapping
files are generated. 

        FB

-- 
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