The HQL should fail because MyValue is not a property of Base.
On Mon, Jun 14, 2010 at 5:40 AM, timjroberts <[email protected]> wrote:
> I have the following entities defined in my Entity Model:
>
> public class MyContainer
> {
> public virtual ICollection<Base> Subs { get; set; }
> }
>
> public abstract class Base
> {
> public virtual Guid Id { get; set; }
> }
> public abstract class Sub1 : Base
> {
> public virtual int MyValue { get; set; }
> }
> public abstract class Sub2 : Base
> {
> public virtual int MyValue { get; set; }
> }
> and the following FluentNHibernate mappings for the above entities:
>
> public sealed class BaseMap : ClassMap<Base>
> {
> public BaseMap()
> {
> Table("BaseTable");
> Id(e => e.Id);
> }
> }
>
> public sealed class Sub1Map : SubClassMap<Sub1>
> {
> public Sub1Map()
> {
> Table("Sub1Table");
> KeyColumn("BaseId");
>
> Map(e => e.Myvalue);
> }
> }
>
> public sealed class Sub2Map : SubClassMap<Sub2>
> {
> public Sub2Map()
> {
> Table("Sub2Table");
> KeyColumn("BaseId");
>
> Map(e => e.Myvalue);
> }
> }
> When I run the following HQL:
>
> select sub
> from MyContainer container
> join fetch container.Subs sub
> where sub.MyValue = :p1
> the SQL generated only applies a constraint in the WHERE clause for
> one of the sub-classes, however, the generated JOINS are correct,
> i.e., the following skeletal SQL is generated:
>
> SELECT ...
> FROM BaseTable bt
> INNER JOIN Sub1Table st1 ON ...
> INNER JOIN Sub2Table st2 ON ...
> WHERE st1.MyValue = @p1
> where as I'm expecting an additional OR in the WHERE clause:
>
> SELECT ...
> FROM BaseTable bt
> INNER JOIN Sub1Table st1 ON ...
> INNER JOIN Sub2Table st2 ON ...
> WHERE st1.MyValue = @p1
> OR st2.MyValue = @p2
> Is there something I'm missing, or is there a way to re-write the HQL
> so that I can reference each sub-class in the WHERE clause and apply
> the constraint directly (assuming that it would then generate the
> additional constraint in the generated SQL)?
>
> I'm using NHibernate 3.0.0.
>
> This question was also posted on Stackoverflow (http://
> stackoverflow.com/questions/3004443/hql-query-over-sub-classes), but
> had no takers.
>
> --
> 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.
>
>
--
Fabio Maulo
--
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.