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