java - Re-attach deserialized hibernate proxies -


i have retrieved database proxy object empp(domain class:employee) hibernate using hql. i'd serialize it(step1) file , deserialize it(step2). step1 , step2 in 2 different threads.

problem in order:

  1. i serialize empp in step1.
  2. in step1 in not serialize attached session of empp in ((proxyobject)empp).gethandler().session, session transient.
  3. in different thread, deserialize empp emppdeserialized , have empp empp.gethandler().getsession() equal null . step2 different session.

now, whenever call getter emppdeserialized, throws could not initialize proxy - no session.

in step2, i'd emppdeserialized attached current session getter calls successful.

now, 1 stupid way can think of is:

    ((org.hibernate.proxy.pojo.javassist.javassistlazyinitializer)((javassist.util.proxy.proxyobject)emppdeserialized).gethandler()) .setsession((org.hibernate.engine.spi.sessionimplementor)sessionfactory.getcurrentsession()); 

question is, i'd know best practice available , least sql calls in step2. in advance.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -