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.  [ 6 posts ] 
Author Message
 Post subject: Criteria API : AddOrder limitation alternatives?
PostPosted: Thu Apr 13, 2006 7:43 am 
Beginner
Beginner

Joined: Fri Jul 29, 2005 10:34 am
Posts: 25
Hibernate version: 1.0.2

Hi,

I think i've hit a limitation in the Criteria API: I can't use AddOrder for subcriterias. In simpler words : I can not sort on a parent (many:1) property Name when using Criteria API.

I've tried all combinations possible and none of them works. This one below is the basic case:

ICriteria _criteria = Session.CreateCriteria(typeof(Products));
_criteria.CreateCriteria("Suppliers", "SPP").AddOrder("CompanyName");


My problem is the same as the following posts (from hibernate, not NHibernate):
http://forum.hibernate.org/viewtopic.ph ... ot+ordered
http://opensource.atlassian.com/project ... wse/HB-132

The only option so far it to use HQL (with an explicit join creating the alias like shown below:
string _hql = "SELECT PRD FROM Products as PRD left outer join PRD.Suppliers as SPP ORDER BY SPP.CompanyName";

Are there other alternatives that i'm missing?

Thanks in advance,
Sebastian


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 9:16 am 
Newbie

Joined: Tue Jul 12, 2005 5:17 am
Posts: 9
Sorry, trilpe post, how can I delete my comments? :-]


Last edited by green_fr on Thu Apr 13, 2006 9:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 9:16 am 
Newbie

Joined: Tue Jul 12, 2005 5:17 am
Posts: 9
The same problem.
Hibernate.3.0.5


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 9:16 am 
Newbie

Joined: Tue Jul 12, 2005 5:17 am
Posts: 9
The same problem.
Hibernate.3.0.5


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 13, 2006 9:25 am 
Beginner
Beginner

Joined: Fri Jul 29, 2005 10:34 am
Posts: 25
NHibernate Changes 1.0.2 (APR 13)

With the changes shown below I could make this syntax (not using SubOrder but still good enough...) to work:

Session.CreateCriteria(typeof(Products));
_criteria.CreateCriteria("Suppliers", "SPP");
_criteria.AddOrder("SPP.CompanyName", true);

Order.cs

Code:
   /// <summary>
   /// Render the SQL fragment
        ///
        /// STA 13-4-2006 : Added new Parameter (aliasClasses) + use it.
      /// </summary>
      /// <param name="sessionFactory"></param>
      /// <param name="persistentClass"></param>
      /// <param name="alias"></param>
      /// <returns></returns>
      //public string ToSqlString( ISessionFactoryImplementor sessionFactory, System.Type persistentClass, string alias )
      public string ToSqlString( ISessionFactoryImplementor sessionFactory, System.Type persistentClass, string alias , IDictionary aliasClasses)
      {
         //string[ ] columns = AbstractCriterion.GetColumns( sessionFactory, persistentClass, _propertyName, alias, emptyMap );
            string[] columns = AbstractCriterion.GetColumns(sessionFactory, persistentClass, _propertyName, alias, aliasClasses);
            if (columns.Length != 1)
         {
            throw new HibernateException( "Cannot order by multi-column property: " + _propertyName );
         }
         return columns[ 0 ] + ( _ascending ? " asc" : " desc" );
      }



CriteriaLoader.cs


Code:
         foreach( Order ord in criteria.IterateOrderings() )
         {
            if( foundOrder )
            {
               orderBy.Append( StringHelper.CommaSpace );
            }
                // STA 13-4-2006 : Modified
            //orderBy.Append( ord.ToSqlString( factory, criteria.CriteriaClass, Alias ) );
                orderBy.Append(ord.ToSqlString(factory, criteria.CriteriaClass, Alias, criteria.AliasClasses ));
            foundOrder = true;
         }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 2:45 pm 
Newbie

Joined: Mon Jun 12, 2006 10:32 am
Posts: 3
I need Hibernate fix for that too


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