-->
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: How to access the list in entity while building criteria qry
PostPosted: Fri Jul 23, 2010 12:35 pm 
Newbie

Joined: Fri Jul 23, 2010 12:12 pm
Posts: 2
Hello All,

I'm new to this hibernate world. I managed to understand a little bit about creation of criteria queries. Now i have a problem:

" How to access the list present in hibernate entity while building criteria query ? "

My Entities
Code:
@Entity
@Table(name = "SERVICE_ORDER_TELE")
public class ServiceOrderTele implements java.io.Serializable, DbEntity {

   private static final long serialVersionUID = -8627659364766032745L;

   private int orderId;
   private ServiceOrder serviceOrder;
   private String xxxOrder;

        << some more code >>
}


@Entity
@Table(name = "service_order")
public class ServiceOrder extends AbstractSelectItemCapableEntity implements java.io.Serializable, DbEntity, TrackChangeEntity, SelectItemCapableEntity
{
   private static final long serialVersionUID = 1677602216424780145L;

        << Some more local variables >>

   private Date issueDate;

   private String status;

   private List<OrderItem> orderItems = new ArrayList<OrderItem>(0);

   private List<ServiceOrderHistory> serviceOrderHistories = new ArrayList<ServiceOrderHistory>(0);

   << Some more variables and functions >>
}



@Entity
@Table(name = "order_item")
public class OrderItem implements java.io.Serializable, DbEntity, TrackChangeEntity, StatusAwareEntity, Cloneable {

   private static final long serialVersionUID = 1677602216424780145L;

   
   private List<OrderItemHistory> orderItemHistories = new ArrayList<OrderItemHistory>(0);
   private ItmUserService itmUserService;
   
   private ItmUser itmUser;
   
   private ItmMb itmMb;

        << Some more of code follows >>
}


Now my problem is when i'm building a criteria query on serviceOrderTele where i want to access itemUser. This will be based on the user selection on the UI

On the Jpa of ServiceOrderTele i'm building criteria. Lets assume user wants all the list of serviceOrderTele where telephone='111-111-1111' and with the service='ABCDE' and with status='Pending'

In the list orderItems of serviceOrder, i know that first item is itmUser and second item is itmUserService
Code:
crit.createAlias("serviceOrder", "so");
crit.add(Restrictions.eq("so.status", "Pending");

// for telephone which is in itmUser of orderItem
crit.add(Restrictions.eq("so.orderItems[0].telephone", "111-111-1111");

// for service which is in itmUserService of orderItem
crit.add(Restrictions.eq("so.orderItems[1].service", "ABCDE");



For this its giving some exception orderItems[1] is not a property of ServiceOrderTele... something like that....

Now i need your help in accessing the orderItems list in building the criteria....

Please tell me whether it is possible or not in the first place...
If possible, can it be done using Criteria Query or HQL

Thanks in advance
Deepak


Top
 Profile  
 
 Post subject: Re: How to access the list in entity while building criteria qry
PostPosted: Mon Jul 26, 2010 11:32 am 
Newbie

Joined: Fri Jul 23, 2010 12:12 pm
Posts: 2
I have got the answer myself...

You just need to create criteria or create alias inorder to use the entity.

Code:
crit.createAlias("serviceOrder", "so");
crit.createAlias("so.orderItems", "ois");
crit.createAlias("ois.itmUser", "iu");

// then you can use this iu in ur restriction
crit.add(Restrictions.eq("iu.telephone", "111-111-1111");


Similarly for the itmUserService.


Thanks
Deepak


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.