So I'm using Hibernate 3.0.5 with Postgres 8.0.4, and I'm encountering a problem where ordering by a composite object produces invalid SQL. I have the following mapping:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="com.sourcelabs.tpccOM">
<class name="NewOrder" table="new_order">
<composite-id name="orderId" class="OrderId">
<key-many-to-one name="district" class="com.sourcelabs.tpccOM.District">
<column name="no_w_id"/>
<column name="no_d_id"/>
</key-many-to-one>
<key-property name="o_id" column="no_o_id" type="integer"/>
</composite-id>
<one-to-one name="order" class="com.sourcelabs.tpccOM.Order"/>
</class>
</hibernate-mapping>
and I'm creating a query using the following call:
Code:
return getSession().createQuery("from NewOrder as no where no.orderId.district.districtId.d_id=?" +
" and no.orderId.district.districtId.warehouse=?" +
" order by no.orderId asc")
.setInteger(0, districtId)
.setInteger(1, warehouseId)
.setFetchSize(2)
.iterate();
It produces an ORDER BY clause that looks like this:
Code:
order by (neworder0_.no_w_id, neworder0_.no_d_id, neworder0_.no_o_id) asc
The correct SQL would look like this:
Code:
order by neworder0_.no_w_id asc, neworder0_.no_d_id asc, neworder0_.no_o_id asc
So my questions are:
* Is this createQuery syntax considered to be invalid HQL? SHOULD it work?
* Or should Hibernate throw an error here?
(Stating the column names specifically in the order by clause, instead of stating the composite ID, works as expected.)
If this is a bug, I'd really like to work on fixing it. I've started digging into the Hibernate source, but I'm not too sure where to start. By the same token, if Hibernate should throw an exception here, I'd like to work on creating a patch that does that. I've started looking at the Hibernate source and trying to figure out how to do this, but I'd really appreciate input on this from the developer community first.
Also, if this is a bug, any information on how the query parser works and where to start with an eye towards fixing this would be appreciated. I've been looking at the ANTLR grammars and the relevant Java classes, but it's a lot to absorb and some pointers would help.
Thank you very much for your time!