-->
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.  [ 3 posts ] 
Author Message
 Post subject: Criteria query for a collection based on a value in the coll
PostPosted: Sat Oct 01, 2005 4:57 pm 
Newbie

Joined: Thu May 26, 2005 1:04 pm
Posts: 13
I am trying to implement criteria query for a search results for an application.This is pretty trivial when using HQL but I am not able to do the same in criteria queries.

Any help would be greatly appreciated.

How do I write criteria query for this????

Code:
Class A{
    Collection colB

}
Class B {
    Object A
    Date date
}

What I want to do is
Code:
(select a from A inner join B b where b.date = (select max(date) from B where b.a = a)))

_________________
RT


Top
 Profile  
 
 Post subject: Re: Criteria query for a collection based on a value in the
PostPosted: Sat Oct 01, 2005 4:58 pm 
Newbie

Joined: Thu May 26, 2005 1:04 pm
Posts: 13
rtarar wrote:
I am trying to implement criteria query for a search results for an application.This is pretty trivial when using HQL but I am not able to do the same in criteria queries.

Any help would be greatly appreciated.

How do I write criteria query for this????

Code:
Class A{
    Collection colB

}
Class B {
    Object A
    Date date
}

What I want to do is
Code:
(select a from A inner join B b where b.date = (select max(date) from B where b.a = a)))


Error in the prev query... read this instead
(select a from A as a inner join B as b where b.date = (select max(date) from B where b.a = a)))

_________________
RT


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 7:22 am 
Newbie

Joined: Sat Jul 23, 2005 8:31 am
Posts: 18
the following code should work more or less.


DetachedCriteria maxDate = DetachedCriteria.forClass(B.class)
.setProjection( Property.forName("date").max() );

session.createCriteria(A.class)
.createCriteria("colB", "b")
.add( Property.forName("b.date").eq(maxDate) );


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