-->
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.  [ 2 posts ] 
Author Message
 Post subject: Assocation Problem
PostPosted: Wed Jun 13, 2007 2:19 am 
Newbie

Joined: Tue Jul 11, 2006 10:41 pm
Posts: 11
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 13, 2007 2:52 am 
Newbie

Joined: Tue Jul 11, 2006 10:41 pm
Posts: 11
i think i found the problem for this


-- begin transaction

select stock from com.Stock as stk inner join fetch stk.warehouseSets as whs where whs.wh_id = '0001' and stk.id = 'A' " --> give me 0001



select stock from com.Stock as stk inner join fetch stk.warehouseSets as whs where whs.wh_id = '0002' and stk.id = 'A' " ---> give me 0001 which is WRONG
//do some other work


--- commit transaction

as you can see from the bold statement the second query give me 0001 as well which is wrong ( running in the same session )

i think hibernate internally using caching that causes this problem to occurs

How to fix /turn off the hibernate caching hibernate use?

Thanks


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

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.