-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Query Criteria to output a Join Table and get spec
PostPosted: Mon Jul 25, 2011 2:32 am 
Newbie

Joined: Mon Jul 25, 2011 2:25 am
Posts: 1
I have a table cartitems where the items added to the cart are stored in. It has columns:

id (Primary Key), sku, quantity, userId, status, size and couple of other columns

I also have a productAvailability table in which we store Inventory levels and where I have following columns:

Quote:
sku, size , quantity, BatchId (Primary Key)

Also product table has one-to-many relationships with productAvailability table and cartitems table both on the sku key


Now, for each cartitems with status = 1 and userId=x we need to check the availability of the product and if available, I need the CartItems row and the BatchId of the product:

I got till here:

Code:
   Criteria criteria = session.createCriteria(CartItems.class,"cartitems");
                criteria.add(Restrictions.eq("userId", userId));
              criteria.add(Restrictions.eq("status", status));
              criteria.createAlias("product", "product");
              criteria.createAlias("product.productAvailability", "productavailability");
              criteria.add(Restrictions.eqProperty("productavailability.size", "cartitems.size"));
              criteria.add(Restrictions.geProperty("productavailability.quantity", "cartitems.quantity"));
                        List<CartItems> cartItems =  criteria.list();



The above basically does following:

Code:
    select * from cartItems
        where productAvailability.quantity >= cartitems.quantity and
              productAvailability.size = cartitems.size and
              productAvailability.sku = cartitems.sku and
              cartitems.userId = ? and
              cartitems.status = ?


This way I cannot get the BatchId. I tried using JOIN FETCHTYPE but it still loads productAvailability table with all sizes of an sku. Is there any way for me to get both cartItems and corresponding BatchId for each cartItem?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.