-->
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.  [ 3 posts ] 
Author Message
 Post subject: Select count() problems in HQL iwth composite-id
PostPosted: Fri Apr 16, 2004 3:12 pm 
Newbie

Joined: Fri Feb 20, 2004 5:16 pm
Posts: 1
Location: Point Pleasant, NJ
I've run across a problem in Hibernate where when trying to use count(foo) on a mapped object that has a composite key generates the following exception:
Quote:
Code:
net.sf.hibernate.QueryException: path expression ends in a composite value: personte0_ [select count(p) from PersonTestSectionPost as p]

I'll get this error when trying to:
Code:
select count(p) from PersonTestSectionPost as p

My abbreviated mapping file looks like this:
Code:
<class name="PersonTestSectionPost" table="PRSN_TST_SCTN_PST">
   <composite-id unsaved-value="any">
      <key-many-to-one name="prsnTestSection" class="PersonTestSection">
         <column name="PRSN_ID_NO"/>
         <column name="PRSN_RLE_TYP_CDE"/>
         <column name="TST_ADM_MO_NO"/>
         <column name="TST_ADM_YR_NO"/>
         <column name="TST_SCTN_CDE"/>
      </key-many-to-one>
      <key-property name="psnTstSctnSeqNo" column="PRSN_TST_SCTN_SEQ_NO" type="java.lang.Long"/>
   </composite-id> 
   
   <property column="PRSN_TST_SCTN_BOOK_SER_NO" name="bookSerNo" type="java.lang.Long"/>

   <!-- rest of mapping omitted for brevity -->
</class>

If I do select count(*) instead, it works.

However, if a mapped object doesn't use a composite key, then count(foo) works. For instance, this abbreviated mapping file works:
Code:
<class name="Person" table="PRSN">
   <id name="id" type="org.ets.k12.persistence.hibernate.LongSequence" column="PRSN_ID_NO" unsaved-value="null">
      <generator class="assigned" />
   </id>
   
   <property name="firstName" type="java.lang.String" column="PRSN_FST_NAM"/>
   <property name="middleName" type="java.lang.String" column="PRSN_MID_NAM"/>
   <property name="lastName" type="java.lang.String" column="PRSN_LST_NAM"/>

   <!-- rest of mapping omitted for brevity -->
</class>

With this mapping file, I can call this HQL:
Code:
select count(p) from Person
without any error.

Both mapping files have set one-to-many, many-to-one, and straight property maps.

We are using Hibernate 2.1RC1, against an Oracle 9i database. Anyone have any ideas?

_________________
"I love senselessly pushing things!"


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 16, 2004 4:42 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
id name="id"

you can't use "id" change property name, but i'm not sure the problem is here....


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 16, 2004 11:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Simplest solution is:

Code:
select count(*) from PersonTestSectionPost


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.