Restricting hibernate's eager fetch beyond DAO
I have my entities as ProductType,Product and ProductInventory.
I have a join query to fetch list of inventory for a specific date range which joins Product and ProductInventory. I've got list of object arrays which I have casted and set it ready.
Now from DAO I return the list of products.
In my layer above, if I execute product.getProductInventory() it is actually firing a query again getting all the inventory an开发者_如何学Cd not those inventory as got by the join.
final StringBuilder queryString = new StringBuilder(
"from Product As rsProduct left outer join rsProduct.inventoryList "
+ "as inventory where rsProduct.efDate <= :travelEndDate AND rsProduct.expDate >= :travelStartDate AND rsProduct.locatiion = :LOCN AND rsProduct.id in (:productsIdList) and inventory.bookDate between :startDate and :endDate");
Ex. Say travel start date is 20th Jan and travel end date is 21 Jan. I get only two records here which is perfect.
But after i return to other layer, if i say product.getInventory() it fetches all inventory irrespective of dates.
Can someone address this problem?
You should define a filter and enable it before accessing the collection.
精彩评论