I'm having trouble working out how to write a query where I need to select against a value in a collection of composite elements.
This is the mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ourcommunity.article.dao.ArticleDO" table="Article">
<cache usage="read-write" />
<id name="id" type="int" column="ID" unsaved-value="0" >
<generator class="identity"/>
</id>
<version name="version" type="long" />
<property name="enabled" />
<set name="categories" table="ArticleCategory" cascade="all">
<cache usage="read-write" />
<key column="OrgID"/>
<composite-element class="ourcommunity.category.dao.WeightedCategoryDO">
<property name="weight" />
<property name="categoryId" />
</composite-element>
</set>
</class>
</hibernate-mapping>
and this is the query I tried:
Code:
SELECT
a
FROM
ourcommunity.article.dao.ArticleDO a,
ourcommunity.category.dao.WeightedCategoryDO ac
WHERE
a.enabled=1
AND ac in elements(a.categories)
AND ac.categoryId=?
But when I run the query to SQL get sent to the DB and this message in the logs:
Code:
WARN [QueryTranslator] no persistent classes found for query class: SELECT a FROM ourcommunity.article.dao.ArticleDO a, ourcommunity.category.dao.WeightedCategoryDO ac WHERE a.enabled=1 AND ac in elements(a.categories) AND ac.categoryId=?
What is the correct way to do this query in HQL? Or do I have to do an SQL query?
Thanks