-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: [HQL] Problem with accessing id property in a select section
PostPosted: Thu Apr 27, 2006 11:21 am 
Newbie

Joined: Thu Apr 20, 2006 9:35 am
Posts: 10
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 1:07 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I wonder if it's possible that hibernate is getting confused because you've explicitly used the builtin property name "id". Try the query with all the joins listed, see if that resolves things:
Code:
SELECT c.id
from Company cny
join cny.relatedCompanies rc
join rc.Company c
WHERE cny.id = '"+session.getCompany().getId()+"'

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 2:58 am 
Newbie

Joined: Thu Apr 20, 2006 9:35 am
Posts: 10
Thanks a lot that works fine!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 30, 2006 5:23 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Great! Then you'll be pressing the little green "Yes" link any time now. Thanks!

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.