Hi,
Suppose i have 3 tables ( STOCK , WAREHOUSE , STOCK_WAREHOUSE_MAPPING )
and data as below
STOCK
---------
ID MAT
-- ----
1 A
2 B
WAREHOUSE
----------------
0001
0002
0004
STOCK_WAREHOUSE_MAPPING
------------------------
STOCK_ID WAREHOUSE_ID
1 0001
1 0002
2 0004
and i have Stock.java and Warehouse.java and each class have coressponding java.util.Set to define bidirectional assocation between two
my HQL as below
List l = "select stock from com.Stock as stk inner join fetch stk.warehouseSets as whs where whs.wh_id = '0002' and stk.id = 'A' "
l.size() ---> prints 1 which is correct
Stock stk = l.get(0);
stk.getWarehouseSets().size() ----> print 1 only which is 0001 which is WRONG
my workaround to that is
i change the lazy="false" in assocation relationship in my Stock.hbm.xml
and change HQL as below
List l = "select stock from com.Stock as stk where stk.warehouseSets.wh_id = '0001' and stk.id = 'A' "
l.size() ---> prints 1 which is correct
Stock stk = l.get(0);
stk.getWarehouseSets().size() ----> print 2 only which is CORRECT NOW
My Question is there any equivalent lazy fetching using pure HQL without
changing the hbm xml??
Thanks
|