3

I am developing a Java EE application to be deployed on a WebSphere application server. In this application, I have a Web Service, through which I would like to transfer JPA entity objects as results of method invocations. The problem comes from the loops generated by entity relationships.

I have used Eclipselink Moxy in order to solve the problem of inverse references between the JPA entities. However, since I am not calling the JAXB implementation myself, but WAS calls its own, the @XmlInverseReference annotation gets ignore. I don't want to use the @XmlTransient annotation since it is important for me to fetch all the referenced entities as method result.

Is it possible to use Moxy as default WebSphere JAXB implementation? Or, can I create JAXB adapters for my entities which would then at runtime add @XmlTransient annotations? I need this since I have methods which return the entities referencing other entities, but also returning the referenced entities with their references towards the sources of the database relationships.

dpesic
  • 29
  • 2

1 Answers1

1

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.

There is no requirement in JAX-WS implementations that they be able to swap in alternate JAXB implementations. One option in environments that don't support MOXy as the JAXB provider in JAX-WS is to use the standard Provider mechanism.

One trick you could try to replace the need for @XmlInverseReference annotation is to leverage the unmarshal event call back mechanism. This involves putting the following method on the child object. In the implementation of that method you could set the reference to the parent.

void afterUnmarshal(Unmarshaller, Object parent);

Note: You will need to annotate that property with @XmlTransient.

MOXy can be used as the JAXB provider for JAX-WS in the following environments:

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • Thank you very much for your answer. The option with the implementation of the afterUnmarshal method does not work for me, because my marshalling needs to work both ways, from parent to child and vice versa, which means that I cannot use @XmlTransient anywhere. Can you provide a bit more info on how to install the Moxy as the JAXB provider in WebSphere? – dpesic Dec 05 '12 at 16:11
  • There's a typo in the @XmlInverseReference annotation - SO doesn't accept edits with less than 6 chars :( – Jacek Laskowski Dec 06 '12 at 23:41
  • @JacekLaskowski - Thank you for pointing out the typo, it is now fixed. – bdoughan Dec 06 '12 at 23:47