I'm using Hibernate 2.1.1.
The mapping files were generated by Middlegen R3.
------------------
Mapping file
------------------
Documento
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="vo.Documento"
table="documento"
>
<id
name="id"
type="long"
column="id"
>
<generator class="increment" />
</id>
<property
name="nome"
type="java.lang.String"
column="nome"
length="-1"
/>
<!-- associations -->
<!-- bi-directional one-to-many association to VersaoDocumento -->
<set
name="versaoDocumentos"
lazy="true"
inverse="true"
cascade="delete"
>
<key>
<column name="documento_fk" />
</key>
<one-to-many
class="vo.VersaoDocumento"
/>
</set>
</class>
</hibernate-mapping>
VersaoDocumentoCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="vo.VersaoDocumento"
table="versao_documento"
>
<composite-id name="comp_id" class="vo.VersaoDocumentoPK">
<key-property
name="id"
column="id"
type="long"
length="8"
/>
<!-- bi-directional many-to-one association to Documento -->
<key-many-to-one
name="documento"
class="vo.Documento"
>
<column name="documento_fk" />
</key-many-to-one>
</composite-id>
<property
name="descricao"
type="java.lang.String"
column="descricao"
length="-1"
/>
<!-- associations -->
</class>
</hibernate-mapping>
------------------
Testing code
------------------
Code:
( ... )
List res = session.createCriteria(Documento.class)
.setFetchMode("versaoDocumentos", FetchMode.EAGER)
.createCriteria("versaoDocumentos", "vd")
.add(Expression.eq("vd.comp_id.documento.id", documento_id))
.addOrder(Order.asc("comp_id.id"))
.list();
( ... )
When I execute this query I get:
Code:
java.lang.UnsupportedOperationException: subcriteria cannot be ordered
at net.sf.hibernate.impl.CriteriaImpl$Subcriteria.addOrder(CriteriaImpl.java:70)
( ... )
I want to retrieve a
Documento with an initialized "set" of
versaoDocumentos (versaoDocumentos should come ordered by id) filtering by
documento_id.
Please help.