Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
NHibernate Join Unexpected behavior with Mappings By Code
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Juan Carlos Correa  
View profile  
 More options Jun 14 2012, 10:14 am
From: Juan Carlos Correa <jccorreaf...@gmail.com>
Date: Thu, 14 Jun 2012 07:14:40 -0700 (PDT)
Local: Thurs, Jun 14 2012 10:14 am
Subject: NHibernate Join Unexpected behavior with Mappings By Code

I am a developer from Florida, USA. We are big fans of NHibernate
(3.3.1.4000) and also we are very happy to work with the .NET version. We
recently found something but we are not sure if it is bug. We have made
several test with different variants but still got the same unwanted
results. This is the description:

We need to map 3 tables to one class with Mapping By Code using the fluent
API.

This is the basic mapping for the principal table

           // schema
            Schema("dbo");
            // table
            Table("TEST_Principal");
            // id
            Id(i => i.Id, m => m.Column("PrincipalID"));

and we want to get properties from two more tables. So we do

            Join(
                "TEST_PrincipalExtra",
                m => {
                    m.Key(k => { k.Column("PrincipalExtraID"); });
                    m.Property(i => i.Prop1, n => { n.Column("Column1"); });
                });
// and
            Join(
                "TEST_Principal_Aud",
                m => {
                    m.Key(k => { k.Column("Principal_AudID"); });
                    m.Component(i => i.AuditInformation);
                });
Based on the output from NHibernate profiler we get:

select
/// properties here
from
     TEST_Principal p inner join
     TEST_PrincipalExtra pe on p.PrincipalID = a.Principal_AudID inner join
     TEST_Principal_AuditID a on p.PrinciaplID = a.Principal_AudID

Notice how it correctly gets the tables for the join and also it associates
correctly the columns from each table. But the m.Key statement from the
second join overrides the previous one and makes the query fail because the
ID for TEST_PrincipalExtra is not Principal_AudID. We have found that if
you swap the order of the join statements then we get the same error but
now on TEST_Principal_Aud. So NHibernate stays with the last Key statement.
 But if we do the mapping on xml it works perfectly.

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

2.2">

    <class name="TESTPrincipalClass" table="TESTPrincipal">

        <id name="Id" column="PrincipalID" />

        <join table="TEST_PrincipalExtra">
            <key column="PrincipalExtraID" />
            <property name="Prop1" column="Column1" />
        </join>

        <join table="TEST_Principal_Aud">
            <key column="Principal_AudID" />
            <component name="AuditInformation" />
        </join>
    </class>
</hibernate-mapping>

Thanks for your time.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »