I have the fallowing mapping:
<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 is declared as follows:
<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>
Now I try to create a select with hql which should return all Countries, with the fallowing “normal” 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%'
When I create the hql like
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
and set the parameter val to a%
I get the following QueryException:
could not resolve property: EntityId of: Prayon.Entities.LocalizedProperty
[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]
I hope someone can help me how to setup my hql.
Any “any”-type has two special properties “id” and “class”, so you should be able to do something with them like this
Im not 100% sure the above is correct as i don’t see exactly what you are doing. A discussion about whether you really need any for the kind of localization you seem to be doing would be good i think.
Nevertheless i am pretty sure .id and .class is the key to solve your immediate challenge.