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 :

  1. i hit my.domain.com
  2. i redirected instance 1 (apache decides instance 1 )
  3. log in
  4. shut down instance 1
  5. refresh page
  6. 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

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -