-->
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: order-by issue
PostPosted: Fri Apr 28, 2006 11:33 am 
Newbie

Joined: Fri Apr 28, 2006 10:55 am
Posts: 1
Hello,

I have a class that has a collection of objects as a property.
I'm using a "link" table/class (IDs map) between the parent class and the collection.

I don't know how to order the collection based on a property of the actual object (not of the "link" class).

See below my mapping file.
I want to order the SiteOptionsList collection by the OptionText property of the SiteOptionChild class.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
 
  <class name="SiteOptionsParent" table="SiteOptions">
    <id name="OptionID" type="Int32">
      <generator class="identity" />
    </id>
    <property name="OptionText" type="String(128)"/>
    <bag name="SiteOptionsList" lazy="false" order-by="?????????">
      <key column="ParentOptionID"/>
      <one-to-many class="SiteOptionsRel"/>
    </bag>
  </class>
 
  <class name="SiteOptionsRel" table="SiteOptionRel">
    <id name="RowID" type="Int32">
      <generator class="identity" />
    </id>
    <property name="ParentOptionID" type="Int32" />
    <many-to-one name="Child" column="ChildOptionID" class="SiteOptionChild" unique="true" />
  </class>

  <class name="SiteOptionChild" table="SiteOptions">
    <id name="OptionID" type="Int32">
      <generator class="identity" />
    </id>
    <property name="OptionText" type="String(128)" />
  </class>
 
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 28, 2006 12:40 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
You would not be able to use order-by here unless the field you want to order by is in the SiteOptionsRel table. You will most likely have to use HQL:

Code:
return session.CreateCriteria(typeof(SiteOptionsRel))
    .Add(Expression.Eq("SiteOptionsParent", siteOptionsParent))
    .CreateCriteria(typeof(SiteOptionsChild))
        .AddOrder(Order.Asc("OptionText"))
    .List();


At one point earlier in the NH lifecycle, this was not supported (nested criteria). I thought I saw somewhere that Sergey has implemented this. Otherwise you'll probably have to do some heavy duty CreateQuery() stuff.


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.