Hi, Developers,
I am reading Hibernate in Action book. page 300-304.
in this part, the book is about thread local seesion pattern.
From HibernateUtil code:
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
looks like all request will share the same seesion.
This is what I am confuesed, if 2 different users place bid at the same time, they will use the same threadSession, right?
So if my thought is right, The problem will be here.
From void dofilter() { // (page 304)
.......
......
finally {
HibernateUtil.closeSession();
}
}
After the first user rendered the view, the session will be closed. then the second user has not rendered the view, the newbid.getBidder().getItems().iterator() is unfetched at this point because of items association is lazy.
How to fix this issue?
if ThreadLocal threadSession is not static, so the different will have different session? right.
Thank you much for your help!
Edgy
|