-->
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: Object containing list of object
PostPosted: Wed Aug 03, 2011 11:28 am 
Beginner
Beginner

Joined: Wed Nov 03, 2010 1:05 pm
Posts: 24
Hello,

I've two object, Risk and action. Actually Risk(id, summary, list<Action> actionsList) contains a list of actions(id, dueDate)

I would like to create a request using criteria in order to retrieve only risks which contains one or more actions with a specific due date.

I don't know how can I point the dueDate in the criteria, smthing like that:
Code:
criteria = criteria.add(Restrictions.le("actions.duetDate", date));


can someone help me on this?
thx :-)

I got the response:
Code:
      List<Risk> riskList =
        session.createCriteria(Risk.class)
           .createAlias("actions", "action")
           .add(Restrictions.eq("action.dueDate", date))
           .add(Restrictions.ne("action.status", "100%"))
           .addOrder(Order.asc("action.dueDate"))
           .list();


Top
 Profile  
 
 Post subject: Re: Criteria: Object containing list of object
PostPosted: Thu Aug 04, 2011 3:59 am 
Beginner
Beginner

Joined: Wed Nov 03, 2010 1:05 pm
Posts: 24
Someone know how to create request using criteria for this sql statement?

Code:
select * from risks r join actions a
on r.id = a.p_id
and
r.v_no = a.v_no
where a.owner = 'azeazeaze'
and
a.id = (select min(aa.id) from actions aa where aa.p_id=r.id )




Here is the response:
Code:
      DetachedCriteria avgWeightForSex = DetachedCriteria.forClass(Action.class, "action2")
      .setProjection( Property.forName("action2.pk.id").min() )
      .add( Property.forName("action2.pId").eqProperty("action.pId") );

      objects=session.createCriteria(Risk.class, "risk")
      .createAlias("actions", "action")
      .add( Property.forName("action.pk.id").eq(avgWeightForSex) )
      .add(Restrictions.eq("action.targetDate", new Date()))
      .add(Restrictions.ne("action.status", "100%"))
      .addOrder(Order.asc("action.targetDate"))
      .list();


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.