-->
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: How to use Criteria for query
PostPosted: Mon Feb 16, 2004 11:00 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
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>


VersaoDocumento
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.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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 4:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is not supported. There is an existing feature request in JIRA.

Use HQL instead.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 8:30 pm 
Newbie

Joined: Thu Apr 22, 2004 7:45 pm
Posts: 2
Location: Des Moines, Iowa, US
gavin wrote:
This is not supported. There is an existing feature request in JIRA.


I believe this is the open Jira issue: Order support for joined Criteria


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.