views:

266

answers:

1

I have an entity which might have a parent entity. I want to run this query:

select entity where entity.parent.id = 9

some of the entity does not have parents (entity.parent = null) and N HIBERNATE Fails to run this query (QueryException - Could not resolve property)

How can I use HQL to get all the entities that has parents entities with id 9, avoiding the ones that the parent is null ?

(adding entity.parent is not null before the entity.parent.id = 9 results in the same exception)

There is an option to use a nested select statements but I don't think this is the most efficient solution.

+1  A: 

You are missing a from clause in your HQL query. Try rewriting it like this:

from entity where entity.parent is not null and entity.parent.id = 9

Not sure, but probably the entity.parent is not null part is not necessary. I suppose NHibernate will handle this scenario.

Darin Dimitrov
You are probably right (the form exist in the original code) I've found out that there is another problem that causes this error, the praent has a derived class that has no mapping to the parent field. I will find a way to remove the derived class from query and than I can check and approve the answer :-)
Dani