-->
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.  [ 5 posts ] 
Author Message
 Post subject: CreateCriteria within CreateCriteria?
PostPosted: Mon May 30, 2005 10:59 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
Trying to do something like this (available in Hibernate 2.1.7):

Code:
IList memberTasks = sess.CreateCriteria(typeof(MemberTask))
   .Add(Expression.Eq("Member", assignee))
   .Add(Expression.IsNull("DateCompleted"))
   .CreateCriteria("Task")
      .AddOrder(Order.Asc("Name"))
   .List();


in the Hibernate docs it looks like this:

Code:
List cats = sess.createCriteria(Cat.class)
    .add( Expression.like("name", "F%")
    .createCriteria("kittens")
        .add( Expression.like("name", "F%")
    .list();


Basically, I am querying the association class, but I need to do an "order by" on one of the fields of a component class. MemberTask is an association class between Member and Task with some extra data.

Any ideas using the CreateCriteria interface? I have a working example based on the CreateQuery interface but I really prefer Criteria.

TIA,

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 12:03 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
ICriteria.CreateCriteria isn't implemented yet. I haven't even looked at it so I can't tell whether it will be hard or not.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 1:26 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
thanks sergey. i looked at the hibernate 2.1.8 code and it appears that there is a subclass that creates a "subcriteria". i'll give it a shot in my own source. if it works, i'll submit to the source tree.

thx,

-d


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 2:45 pm 
Newbie

Joined: Mon Jun 27, 2005 12:06 am
Posts: 18
Location: San Francisco, CA
sergey wrote:
ICriteria.CreateCriteria isn't implemented yet. I haven't even looked at it so I can't tell whether it will be hard or not.


Any guesses now? Is there any other way to sort the entities that come back in a one-to-many relation based on their property?

Something like:

Code:
session.CreateCriteria(typeof(Parent))
       .SetFetchMode("Children", FetchMode.Eager)
       .CreateCriteria("Children")
             .AddOrder(Order.Asc("Value"))
       .List()


I will post my question regarding Criteria.CreateCriteria in the Developer Forums too.

RGab


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 3:07 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
For now, I am using the IQuery interface and dynamically building the queries based on some optional parameters. I looked into implementing the ICriteria.CreateCriteria method myself but didn't have the time I thought it would take to write proper unit tests and submit to the code base.

-devon


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