0 Replies Latest reply on Sep 15, 2007 12:51 PM by Jair Karim Tinoco

    LazyInitializationException when serialize entity in SOAP(XM

    Jair Karim Tinoco Newbie

      Hi,
      There are a common problem, when entities are linked in @OneToMany relationships with FetchType.LAZY attribute always a LazyInitializationException occurs when XML serializer tries to serialize it.

      I think this happens because the XML serializer always access all entity's attributes and because the entity is attached to the hibernate's entity manager when XML serializer tries to serialize it.

      LAZY fetch is very useful when we need to retrieve only some data from an entity and avoid to load all collections it have, if we use EAGER fetch all works perfectly but performance is seriously affected.

      This behavior force to the developer to use ValueObject or Data Transfer Object pattern to avoid this problem, frequently developers need to transfer across the wire in SOAP protocol many entity objects and use one Value Object for every entity is expensive, it would be better use directly only entity beans.

      Maybe if hibernate let us detach manually entities from the entity manager this problem go away and life can be more simple.

      BEA introduces this extension in your implementation of JPA, Hibernate and JBoss could do it too.

      If someone knows how i can avoid to use Value Objects in entities with LAZY fetch to serialize in SOAP your help will be very appreciated.

      Thanks!!

      Jair