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