1 Reply Latest reply: Feb 14, 2013 12:48 PM by r035198x RSS

    marshal instrumented hibernate annoted pojo

    user11138293
      I use the maven InstrumentTask to modify my hibernate pojos for lazy fetching . Now I want to marshal instance of this pojo into xml for which I am using jaxb.

      JAXBContext.newInstance(MyEntity.class)

      fails giving exception
      com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 5 counts of IllegalAnnotationExceptions
      net.sf.cglib.transform.impl.InterceptFieldCallback is an interface, and JAXB can't handle interfaces.
           this problem is related to the following location:
                at net.sf.cglib.transform.impl.InterceptFieldCallback
                at public net.sf.cglib.transform.impl.InterceptFieldCallback 
      can I use jaxb for cglib instrumented pojos ?
        • 1. Re: marshal instrumented hibernate annoted pojo
          r035198x
          I wouldn't expose my entities for auto marshaling with JAXB and sent out to clients. Rather use separate POJOs. It will feel a pain to write the DTO to entity copies but you will make life a lot easier for yourself if you are writing a big project. Also, it is more prudent to expose the entity data via DTOs anyway because the best way to store your data is not always exactly the same way users want to access it. You also close some security loopholes because you handpick which values are made available for each interaction.