-->
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: Criteria based on many-to-one parent...
PostPosted: Thu Sep 01, 2005 1:07 am 
Newbie

Joined: Wed Aug 31, 2005 9:29 pm
Posts: 14
Using the standard "Cacades" example with Parent and Child objects, how would I create a criteria that looks up all children with parents whose name starts with the letter "A"?

In SQL:
Code:
    select *
    from cas_child c
    left join cas_parent p on c.parent_id = p.id
    where p.name like 'A%'


Something like:
Code:
    IList children = session.CreateCriteria(typeof (Child))
        .Add(Expression.Like("SingleParent.Name", "A%"))
        .List();


Obviously dot notation is not supported in the first parameter.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 6:02 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
Not possible with criteria. Use HQL:
Code:
q=session.CreateQuery("select c from cas_child c where c.SingleParent.Name like :name")
q.setString("name","A%")
q.List()

_________________
michal


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.