У меня есть следующее отображение:
<class name="Country" table="Country" lazy="false" >
<cache usage="read-write"/>
<id name="Id" column="Id" type="Guid">
<generator class="assigned"/>
</id>
<property name="Name" column="Name" type="String" length="50" not-null="true" unique="true" />
<set name="LocalizedProperties" where="LocalizedEntityClass = 'Prayon.Entities.Country'" cascade="delete">
<key column="EntityId" foreign-key="none" />
<one-to-many class="LocalizedProperty" />
</set>
</class>
LocalizedProperty объявлен следующим образом:
<class name="LocalizedProperty" table="LocalizedProperty">
<cache usage="read-write"/>
<id name="Id" column="Id">
<generator class="guid.comb"/>
</id>
<property name="CultureName" not-null="true"/>
<property name="PropertyName" not-null="true"/>
<property name="PropertyValue" not-null="true"/>
<any id-type="Guid" name="Entity">
<column name="LocalizedEntityClass" not-null="true"/>
<column name="EntityId" not-null="false"/>
</any>
</class>
Теперь я пытаюсь создать выборку с помощью hql, которая должна вернуть все страны, сследующий "обычный" SQL-Select
select *
from Country a
where (
select top 1 PropertyValue
from LocalizedProperty x
where x.EntityId = a.Id
and x.PropertyName = 'Name'
and x.LocalizedEntityClass = 'Prayon.Entities.Country'
and x.CultureName = 'de')
Like 'a%'
Когда я создаю hql как
from Country a
where (
select PropertyValue
from LocalizedProperty x
where x.EntityId = a.Id
and x.PropertyName = 'Name'
and x.LocalizedEntityClass = 'Prayon.Entities.Country'
and x.CultureName = 'de' take 1)
Like :val
и устанавливаю для параметра val значение%
, я получаю следующее QueryException
:
не удалось разрешить свойство: EntityId из: Prayon.Entities.LocalizedProperty [из страны a где (выберите PropertyValue из LocalizedProperty x, где x.EntityId = a.Id и x.PropertyName = 'Name 'и x.LocalizedEntityClass =' Prayon.Entities.Country 'и x.CultureName =' de 'take 1) Like: val]
Я надеюсь, что кто-то может помочь мне, как настроить мой hql.