-->
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.  [ 2 posts ] 
Author Message
 Post subject: Ordering by value(s) of collection Set<String>
PostPosted: Wed Dec 08, 2010 4:15 pm 
Newbie

Joined: Wed Dec 08, 2010 3:49 pm
Posts: 2
Hello,

I have a query which I am trying to sort alphabetically by the String values in a (mapped) collection which is a member of a mapped persistent class. The collection is loaded using a named SQL-query with load-collection set, and the collection is defined as a set in the hibernate mapping definition. The class property is defined as Set<String>.

Now I need to use an ORDER BY statement in HQL to alphabetically order the Invoice records by the values in the collection. The query I'm trying is:

Code:
SELECT i  FROM Invoice i WHERE i.deleted=0 ORDER BY i.shipToBranchNames ASC


This produces the error ORA-00936: missing expression from Oracle. I've also tried:

Code:
SELECT i  FROM Invoice i LEFT JOIN i.shipToBranchNames AS branchNames WHERE i.deleted=0 ORDER BY branchNames ASC


Which gives the error ORA-00942: table or view does not exist.

I've researched and researched this topic, and I can't for the life of me find any documentation regarding sorting alphabetically on items in a collection. No, I don't need to sort the collection itself, it's already doing that fine; I just need a list of invoices sorted by the name(s) of the branch(es) associated with it.

The relevant XML for the schema is:

Code:
<hibernate-mapping>
  <class name="org.bah.common.Branch" table="Branches">
    <id name="id" type="long" column="branchId" >
      <generator class="native"/>
    </id>
    <property name="name">
      <column name="name"  not-null="true" length="255"/>
    </property>
    <property name="displayNameId" column="displayNameId"/>
    <property name="deleted">
      <column name="isDeleted" index="branches_deletedIndex" default="0"/>
    </property>
  </class>

  <class name="org.bah.acquisitions.Invoice" table="Invoices">
    <id name="id" type="long" column="invoiceId" >
      <generator class="native"/>
    </id>
    <set name="shipToBranchNames" cascade="none" inverse="true" fetch="subselect">
      <key column="invoiceId" not-null="true"/>
      <element column="name" type="java.lang.String" not-null="true" unique="true"/>
      <loader query-ref="invoiceShipToBranches"/>
    </set>
  </class>

  <sql-query name="invoiceShipToBranches">
      <load-collection alias="b" role="org.bah.acquisitions.Invoice.shipToBranchNames" lock-mode="read"/>
      SELECT DISTINCT INVOICEID, b.BRANCHID, m.NAME
      FROM OrderItems oi
        JOIN Branches b ON oi.SHIPTOBRANCHID=b.BRANCHID
        JOIN Messages m ON b.DISPLAYNAMEID=m.MESSAGEID
      WHERE oi.INVOICEID=? AND oi.ISDELETED=0
  </sql-query>
</hibernate-mapping>



I appreciate any suggestions and/or help with this issue.

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Ordering by value(s) of collection Set<String>
PostPosted: Thu Dec 09, 2010 10:04 am 
Newbie

Joined: Mon Nov 19, 2007 1:57 pm
Posts: 14
Code:
SELECT i  FROM Invoice i LEFT JOIN i.shipToBranchNames AS branchNames WHERE i.deleted=0 ORDER BY branchNames.name ASC


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