I have just tested this:
* I have the same filters defined in the mappings for both Foo and
Bar.
* I have a mapping on Foo like so:
<many-to-one cascade="all" class="Core.Entities.Bar, Core,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" foreign-
key="Bar_FK" name="FoosBar" property-ref="EntityId">
<column name="FoosBar_id" />
</many-to-one>
* I load a Foo entity:
Foo newFoo =
session.CreateCriteria<Foo>().SetMaxResults(1).List<Foo>().First<Foo>();
* Make sure NH loads the bar.
Bar newBar = newFoo.FoosBar;
The query to load the Bar object *does not* have the filter applied.
How can I make that happen?
On Mar 16, 2:26 pm, snicker <[email protected]> wrote:
> The filter is already defined in the Bar class, and it does not get
> filtered. What ends up happening is it returns too many rows for the
> referenced EntityId because the filter ensuring a unique result is not
> applied.
>
> Why does it have to be explicit? Collections can have filters and be
> lazy loaded... why can't a many-to-one reference?
>
> On Mar 16, 2:21 pm, Fabio Maulo <[email protected]> wrote:
>
> > Then the many-to-one should be explicitly joined in the HQL.
>
> > from Foo f join f.Bar
>
> > The filter must be declared in Bar class.
>
> > 2010/3/16 Fabio Maulo <[email protected]>
>
> > > What you need is only put the filter in the related class, not in the
> > > many-to-one.
>
> > > 2010/3/16 snicker <[email protected]>
>
> > >> I am using 2.1.2.4000. NH throws a MappingException when I put a
>
> > >> filter element in the many to one element in my mapping. Is there
> > >> something specific I should be doing?
>
> > >> On Mar 16, 11:31 am, Fabio Maulo <[email protected]> wrote:
> > >> > NH2.1.2
>
> > >> > 2010/3/16 snicker <[email protected]>
>
> > >> > > I have seen some posts in the nhibernate-development mailing list
> > >> > > about using filters on Many To One relationships. Can anyone tell me
> > >> > > if this is possible, and in what version of NH? are there workarounds
> > >> > > if not?
>
> > >> > > --
> > >> > > 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]>
> > >> <nhusers%[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]<nhusers%[email protected]>
> > >> .
> > >> For more options, visit this group at
> > >>http://groups.google.com/group/nhusers?hl=en.
>
> > > --
> > > Fabio Maulo
>
> > --
> > 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.