hi,
I had 2 entity which is USER and ITEM . the relationship is USER can have many ITEM , but one ITEM only belong to one USER, and I make it bi-direction without join table. both user and item is 2nd level cache enabled.
in my web app, i use spring's openSessionInView Interceptor and i have a page query single item which link to user's information like this :
item.getName(); .... item.getUser().getEmail(); //get the item's user email, if omit this, not SELECT USER statement hit.
my problem is when 2nd level cache enabled, ITEM is cache (so no SQL hit) when i request the item page, but it always follow by a SELECT USER statement, and if i comment the code which is "item.getUser().getEmail();", no SELECT USER statement hit. (mean the select is cause when i get run this code)
so it seem like USER that belong to this ITEM is not get from 2nd level cache.
My question is: 1) seem like the user object is not cache, so it execute an SQL statement every time when i request the item page. 2) if the relationship is inverse, will hibernate fetch the inverse object in 2nd level first ? (i though should be.. but seem like not happening)
any idea ?
kiwi
_________________ happy hacking !
|