Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate Query Criteria to output a Join Table and get specific column  RSS feed

Lucky Murari
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

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:

The above basically does following:

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?
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!