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?