-->
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.  [ 4 posts ] 
Author Message
 Post subject: "Elements" & "Order by" clause
PostPosted: Mon Feb 02, 2004 6:18 am 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
Hello all,

Here's my question :

I have this mapping :
Code:
<hibernate-mapping>
   <class name="StatistiquePersistent" table="STATISTIQUE">
      <id name="numStatistique" column="PK_STATISTIQUE">
         <generator class="sequence">
            <param name="sequence">S_STATISTIQUE_ENR</param>
         </generator>
      </id>
      <property name="entiteId" column="ENTITE_ID" not-null="true"/>
      <many-to-one name="typeStat" column="FK_TYPE_STATISTIQUE" not-null="true" class="TypeStatistiquePersistent"/>
      <set name="statEnregistrements" lazy="true" inverse="true" cascade="save-update">
         <key column="FK_STATISTIQUE"/>
         <one-to-many class="StatistiqueEnregistrementPersistent"/>
      </set>
   </class>
</hibernate-mapping>

<hibernate-mapping>
   <class name="StatistiqueEnregistrementPersistent" table="STATISTIQUE_ENREGISTREMENT">
      <id name="numStatistiqueEnregistrement" column="PK_STATISTIQUE_ENR">
         <generator class="sequence">
            <param name="sequence">S_STATISTIQUE_ENR</param>
         </generator>
      </id>
      <property name="cumul" column="CUMUL" not-null="true"/>
      <many-to-one name="etat" column="FK_ETAT" class="EtatPersistent"/>
      <property name="ordreAffichage" column="ORDRE_AFFICHAGE" not-null="true"/>
      <many-to-one name="statistique" column="FK_STATISTIQUE" class="StatistiquePersistent"/>
   </class>
</hibernate-mapping>


I need to load my "Statistiques" and its set of "StatistiquesEnregistrement" ordered by their "ordreAffichage" property.
My query was :
Code:
queryString = "select listeStat from StatistiquePersistent as listeStat " +
                     "and listeStat.typeStat.libelleTypeStatistique <> :typeStatJournalier " +
                           "group by listeStat.typeStat.numTypeStatistique " +
                           "order by listeStat.typeStat.numTypeStatistique asc, " +
                           "listeStat.statEnregistrements.ordreAffichage asc" ;


And then I had this exception :
Code:
expecting 'elements' or 'indices' after: ordreAffichage



I don't see how to use "elements" with an "order by" clause.
Have someone an hint for me ?

Thanx in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 6:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
where is you where clause.
And I don't think your request can be achieve even on SQL. You grouped by a value and want to order by a non related one. Try do do the SQL one first and do the HQL step by step

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 7:02 am 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
Sorry, I mistaped the query :

Code:
queryString = "select listeStat from StatistiquePersistent as listeStat " +
                     "where listeStat.typeStat.libelleTypeStatistique <> :typeStatJournalier " +
                           "group by listeStat.typeStat.numTypeStatistique " +
                           "order by listeStat.typeStat.numTypeStatistique asc, " +
                           "listeStat.statEnregistrements.ordreAffichage asc" ;


The pb is that in SQL I don't use "elements", so, I don't know how to write my query in SQL :/


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 8:37 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In SQL, you can only select columns that are part of your group by and you can order by the columns that are part of you select. HQL will have such limitations.

My understanding of you problem let me think you break that.

_________________
Emmanuel


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