java - Lazy loading problems with glassfish cluster and JPA -
i having problems when deploy ear glassfish 3.1 cluster. set-up : cluster 1 on host pc 2 instances on 2 vm apache mod_jk load balance between 2 instances (with sticky sessions) tapestry 4.x web app
so problem :
- i hit my.domain.com
- i redirected instance 1 (apache decides instance 1 )
- log in
- shut down instance 1
- refresh page
- apache redirect me instance 2
i storing jpa entity in session (logindata) . entity has lazy loaded properties. when redirected instance 2, have error saying :
exception description: attempt made traverse relationship using indirection had null session. occurs when entity uninstantiated lazy relationship serialized , lazy relationship traversed after serialization. avoid issue, instantiate lazy relationship prior serialization. so guessing @ time object serialized, object still not inflated properties.
if change fetch=eager works expected.
changing eager not option tho...
any ideas how solve issue ?
thanks
storing jpa entity in httpsession bad idea. restrict entity lifetime 1 httprequest , save lot of problems. store entity id in session , use fetch entity on each request. potentially use jpa/hibernate caching options prevent db hit every time.
in situation means after login you'll store @id value of entity in httpsession. when instance 2 tries fetch entity httpsession fetch id , use fetch actual entity within scope of refresh request.
Comments
Post a Comment