Ups sorry... select u.id from User u where u.Username = :username and
:roleName in elements(u.Roles)
SetMaxResult(1).List().Count > 0

My advise is avoid the usage of count(*) in db when what you want know if
exist at least one instance.


2009/10/8 Andy Kernahan <[email protected]>

>
> Thanks for the reply but that will load the entity and it's non-lazy
> associations which I don't want to do. For the mean time I have
> changed the query to select count(*) ... > 0 but this still isn't
> great; can exists not be used?
>
> Andy.
>
> On Oct 8, 7:33 pm, Fabio Maulo <[email protected]> wrote:
> > from User u where u.Username = :username and :roleName in
> elements(u.Roles)
> > SetMaxResult(1).UniqueResult<User>()
> > != null
> >
> > 2009/10/8 Andy Kernahan <[email protected]>
> >
> >
> >
> >
> >
> > > Hi there,
> >
> > > I am trying create a query using HQL which checks to see if a user has
> > > been assigned a certain role. I thought I would be able us:
> >
> > > select exists(from User u where u.Username = :username and :roleName
> > > in elements(u.Roles))
> >
> > > and then call UniqueResult<bool>() on the query object, except
> > > ISession.CreateQuery throws a QuerySyntaxException with the following
> > > message:
> >
> > > Exception of type 'Antlr.Runtime.MismatchedTreeNodeException' was
> > > thrown. near line 1, column 7 [select exists(from
> > > Tss.PIBench.Model.User u where u.Username = :username and :roleName in
> > > elements(u.Roles))]
> >
> > > I have removed the select exists from the statement and queried it to
> > > ensure that it is correct.
> >
> > > Can I not use select exists this way? I would prefer not to have to
> > > select count(*) ... > 0.
> >
> > > The user class is as follows:
> >
> > > class User {
> > >    ISet<string> Roles ...
> > >    string Username ...
> > >    ...
> > > }
> >
> > > Any help would be most appreciated.
> >
> > > Andy.
> >
> > --
> > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to