The discriminator is saved properly, no problem there.

I understand your suggestion, thx for the tip, but I gave here this
simple example just to keep the focus on the "problem". In my project
I have to translate from some sort of custom query language into HQL
for a basic reporting tool in the app.
It is not a real problem that I have to use directly the value of the
discriminator, I have rules to determine it, but I wanted to follow
the "book"; looking at the SQL NH generates I think the discriminator
value has to be used.
Moreover, maybe this problem is a real bug and people developing NH
will see it and fix it :)


On Jan 6, 7:34 pm, ccollie <[email protected]> wrote:
> if that works, then why not something like..
>
> public T Get<T>(int id)
> {
>  var query = session.CreateQuery(hql).SetString("classtype", typeof
> (T).FullName).SetInt32(id);
>  return query.UniqueResult<T>();
>
> }
>
> its ugly, but that ugliness is hidden.
>
> BTW, does the discriminator value get saved properly ?
>
> On Jan 6, 2:52 am, DanV <[email protected]> wrote:
>
>
>
> > It doesn't work  this way either, it seems that nothing gets binded to
> > the parameter and the query is not even executed and an ADOException
> > is raised.
>
> > Using a parameter only seem to work when also setting the value
> > explicitly to the discriminator and using the proper SetXXX statement,
> > e.g in my example it would be:
>
> > var query = session.CreateQuery(hql).SetString("classtype","Wire");
>
> > Thx anyway :)
>
> > On Jan 6, 12:06 am, ccollie <[email protected]> wrote:
>
> > > i havent tried, but how about explicityl setting the type as a
> > > parameter. i.e.
>
> > >  var query = session.CreateQuery(hql).SetParameter("classtype", typeof
> > > (WirePayment));
>
> > > On Jan 5, 4:44 am, DanV <[email protected]> wrote:
>
> > > > Hi,
>
> > > > i'm using NHibernate v 2.1 and I tried query a many to any association
> > > > where I try to get only values of a certain class of the possible
> > > > classes of the "any" part.
>
> > > > I'm using as an example the mappings and classes from Ayende's
> > > > example:
>
> > > >http://ayende.com/Blog/archive/2009/04/22/nhibernate-mapping-ltmany-t...
>
> > > > and I tried, according to NH reference to execute the following query:
>
> > > > select _order.OrderNo, _order.OrderNo
> > > > from Order _order
> > > > left join _order.Payments _payments
> > > > where _payments.class = 'BOLayer.WirePayment, BOLayer'
>
> > > > BOLayer is the assembly and namespace where I declared the classes.
>
> > > > Problem is the query does not return anything.
>
> > > > If instead I write the query like this:
> > > > select _order.OrderNo, _order.OrderNo
> > > > from Order _order
> > > > left join _order.Payments _payments
> > > > where _payments.class = 'Wire'
>
> > > > then I have some results back because NH generates following SQL
> > > > query:
> > > > select order0_.OrderNo as col_0_0_, order0_.OrderNo as col_1_0_ from
> > > > Orders order0_ left outer join OrderPayments payments1_ on
> > > > order0_.Id=payments1_.OrderId where payments1_.PaymentType='Wire'
>
> > > > As far as I could understand from NH reference 
> > > > here:http://nhforge.org/doc/nh/en/index.html#queryhql-where
> > > > NH should be able to translate from the fully qualified name of the
> > > > class to the value of the discriminator declared in mappings.
>
> > > > Am I missing something? The querying only works when using directly
> > > > the value of the discriminator?- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
-- 
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