Announcement Announcement Module
Collapse
No announcement yet.
LazyInitializationException in Hession+Hibernate Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • LazyInitializationException in Hession+Hibernate

    I am developing a Http-based service application adopting Hessian and Hibernate. But when trying to use detached Hibernate object in client side, I got LazyInitializationException all along. From Spring Reference Guide, I knew it's one bug of Hessian as it can't support the complex Hibernate Objects with Collection properties. However, it is very common to have to map out such Hibernate Objects as there must be one-to-many association even in a tiny relational database. RMI are supposed to work nicely with these objects but are not firewall-friendly. The book of Manning in Hibernate suggest to use DTO. Does anyone have better idea for this issue?

  • #2
    If you use the latest version of Hessian (not 2.x or the earlies 3.0.x), you can solve that by not including Hibernate on the client side. That you make the newInstance on the Hhibernate list fails, and Hessian would fall back on java.util.ArrayList.

    If you have to include Hibernate on the client side, there's a few ways you can solve your problem. You can either manage to have your domain object serialize with an ArrayList, or you can extend Hessian classes and add your own serializer for hibernate's list. To modify the hessian's serialization, in the list's setter, you can wrap it in a List implementation that delegates to the hibernate list (e.g. in a Collections.unmodificableList()). You could also use a combinaison of writeReplace/readResolve, that's that would need to create something like a DTO to implement that I guess.

    However, if you want to use Serilization and HTTP, you can use Spring's new HttpInvoker, that's in the org.springframework.remoting.httpinvoker package.

    Guillaume

    Comment


    • #3
      Great, the domain objects now can beuse as Transfer Objects

      HI Guillaume

      Many thanks to your informative comment!!

      Comment

      Working...
      X