1) It _does_ look like a bug, or at least a limitation. I don't know enough
about the internals to tell if NH has enough information to generate the
correct mapping. In either case, you should open a Jira issue.
2) The workaround would be to map two classes with a one-to-one relationship
instead of a <join>
3) I don't know a good answer to that
Diego
On Thu, Aug 12, 2010 at 20:00, George Mauer <[email protected]> wrote:
> I'm working with a legacy schema and therefore using the many-to-one
> property-ref attribute. It seems that this generates incorrect SQL
> when the property referenced is mapped to a joined table in an
> inheritance relationship.
>
> Here is my mapping for the parent class:
>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
> <class name="Domain.RectifierInformation, Domain" table="FACINFO">
> <id name="Id" column="PK_FACINFO" type="System.Guid" unsaved-
> value="00000000-0000-0000-0000-000000000000">
> <generator class="guid" />
> </id>
> <join table="RTINFO">
> <key column="FK_FACINFO" />
> <property name="SecondSourceId" column="PK_RTINFO" not-
> null="true" />
> </join>
> </class>
> </hibernate-mapping>
>
>
> And my mapping for the child class:
>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
> <class name="Domain.RectifierAnode, Domain" table="ANODES">
> <id name="Id" column="PK_ANODES" type="System.Guid" unsaved-
> value="00000000-0000-0000-0000-000000000000">
> <generator class="guid" />
> </id>
> <many-to-one name="Rectifier" class="Domain.RectifierInformation,
> Domain" property-ref="SecondSourceId" column="FK_RTINFO" not-
> null="true" />
> </class>
> </hibernate-mapping>
>
> The query
>
> session.Linq<RectifierAnode>().Where(a=>a.Rectifier.Id ==
> someKnownGuid).Count()
>
> generates the following SQL:
>
> SELECT count(*) as y0_
> FROM
> IANINFO this_
> left outer join FACINFO rectifier1_ on
> this_.FK_RTINFO=rectifier1_.PK_RTINFO
> left outer join RTINFO rectifier1_1_ on
> rectifier1_.PK_FACINFO=rectifier1_1_.FK_FACINFO
> WHERE rectifier1_.PK_FACINFO = @p0
>
>
> This fails on the first join condition. FACINFO doesn't have a
> PK_RTINFO - as I clearly state in the first mapping, this is a column
> on RTINFO. Seems like this might be a bug?
>
> 1) Am I right? Is this a bug?
> 2) Does anyone have any advice for work-arounds (short of changing the
> database schema)
> 3) Why the left outer joins? Where does that come from? An inner
> join would be better.
>
> --
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>
--
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.