Hi,
I have a little problem with a HQL query.
I have a class Company with an id, a descr, and a set of relatedCompanies ( class CompanyRelation that contains a type and a Company ).
When i want to select all the ids of the related companies of a given company, HQL says that he don't know the property 'id'.
Using this query :
Code:
"SELECT cny.relatedCompanies.company.id FROM Company cny WHERE cny.id = '"+session.getCompany().getId()+"'"
If i want the descriptions of thoses related companies, it works good.
Code:
"SELECT cny.relatedCompanies.company.descr FROM Company cny WHERE cny.id = '"+session.getCompany().getId()+"'"
Is it a known bug ?
If it's not, where am i wrong?
Thanks a lot for the replies.
Hibernate version: 3
Mapping documents:Code:
<class name="com.foo.backoffice.Company" table="COMPANY_EA">
<id name="id" type="java.lang.String">
<column name="ID_COMPANY" scale="50" precision="0" not-null="true" sql-type="varchar" />
<generator class="assigned" />
</id>
<property name="descr" type="java.lang.String">
<column name="DESCR_COMPANY" scale="255" precision="0" not-null="true" sql-type="varchar" />
</property>
[...]
<set name="relatedCompanies" table="COMPANY_RELATION_EA" cascade="all" lazy="false">
<key>
<column name="ID_COMPANY"/>
</key>
<composite-element class="com.foo.backoffice.CompanyRelation">
<property name="type">
<column name="RELATION_TYPE" scale="25" precision="0" not-null="true" sql-type="varchar"/>
</property>
<many-to-one name="company" class="com.foo.backoffice.Company">
<column name="ID_RELATED_COMPANY"/>
</many-to-one>
</composite-element>
</set>
Full stack trace of any exception that occurs:Code:
org.hibernate.QueryException: could not resolve property: company.id of: com.foo.backoffice.Company [SELECT cny.relatedCompanies.company.id FROM com.foo.backoffice.Company cny WHERE cny.id = 'foo']
Name and version of the database you are using:
MySQL