I think the persister problem is probably unrelated to the query we're
working on here. I don't know what would be causing that though.... haven't
run into that myself.

On Tue, Jan 13, 2009 at 9:40 AM, mattcole <[email protected]> wrote:

>
> Thanks Will,
>
> Strangely I still get an error about Resource not having a perister
> though.  Even though this code works fine:
>
>            Resource resource = UnitOfWork.CurrentSession.Get<Resource>
> (idOfResource);
>            IQuery query = UnitOfWork.CurrentSession.CreateQuery
> ("select r from Resource r join r.ResourceSet where ResourceContext
> = :resourceContext and r.ResourceSet = :resourceSet");
>            query.SetString("resourceContext",
> resource.ResourceContext);
>            query.SetEntity("resourceSet", resource.ResourceSet);
>            return query.List<Resource>();
>
> Matt
>
> On Jan 13, 4:09 pm, Will Shaver <[email protected]> wrote:
> > You're using a join constrain on your sql instead of a where constrain.
> > Re-write your sql as something like:select r.* from Resource r where
> > r.ResourceContext = (Select ResourceContext from Resource where ID = 1)
> >
> > Then re-write your criteria query in a similar fashion.
> >
> > ICriteria criteria =
> UnitOfWork.CurrentSession.CreateCriteria("Resource");
> > DetachedCriteria dc = DetachedCriteria.For<Resource>();
> > dc.Add(Restrictions.Eq("Id", idOfResource));
> > dc.SetProjection(Property.ForName("ResourceContext"));
> > criteria.Add(Subqueries.Eq("ResourceContext", dc);
> >
> >  -Will
> >
> > On Tue, Jan 13, 2009 at 3:08 AM, mattcole <[email protected]> wrote:
> >
> > > Hi,
> > > I have a scenario where I'd like to use retrieve all instances of an
> > > entity that have a certain property value.  However I want to obtain
> > > that property value from an instance of the entity for which I have
> > > the id.
> >
> > > So in SQL it would look something like:
> >
> > > Select
> > > r.*
> > > From
> > > Resource r
> > > Join Resource r2 on r2.ResourceContext = r.ResourceContext
> > > where
> > > r2.Id = 1
> >
> > > I've tried implementing it as a DetachedCriteria query as follows:
> >
> > >            DetachedCriteria dc = DetachedCriteria.For<Resource>();
> > >            dc.Add(Restrictions.Eq("Id", idOfResource));
> > >            dc.SetProjection(Property.ForName("ResourceContext"));
> > >            ICriteria criteria =
> > > UnitOfWork.CurrentSession.CreateCriteria("Resource");
> > >            criteria.Add(Property.ForName("ResourceContext").Eq(dc));
> >
> > > but I get an exception saying that Resource doesn't have a persister.
> > > (It does, I can otherwise persist and retrieve them).
> >
> > > Is there a way of doing this either through the Criteria API or via
> > > HQL?  I obviously want to avoid having to retrieve the Resource with
> > > the Id first to obtain its ResourceContext.
> >
> > > Thanks,
> > > Matt
> >
>

--~--~---------~--~----~------------~-------~--~----~
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