Is it possible to use @XmlInverseReference where object and property are of same type?

I'm using the MOXy JAXB implementation and make quite extensive use of the @XmlInverseReference annotation. However, I've recently encountered a scenario where this approach doesn't seem to work. If I have a class containing a field with a property that's the same type as the parent class, applying @XmlInverseReference seems to suppress the marshalling of that property altogether. Omitting the annotation yields a predictable StackoverflowException.

Has anybody encountered this problem and discovered an effective solution with MOXy?

A quick sample of the offending class:

public class Person { private Long id; private Person spouse; public Long getId() { return id; } public void setId(Long id) { = id; } @XmlInverseReference(mappedBy="spouse") public Person getSpouse() { return spouse; } public Person setSpouse(Person spouse) { this.spouse = spouse; } }


<strong>EclipseLink MOXy</strong>'s @XmlInverseReference can be used when the object and property are of the same type. The current problem with this use case is that the same property needs to be used for both directions of the relationship.

<strong>What Your Seeing</strong>

When a property is annotated with @XmlInverseReference, for marshalling MOXy will treat that property as being @XmlTransient.

<strong>Enhancement Request</strong>

I have entered the following enhancement request to support this type of behaviour. Please add any additional details that you feel are relevant.

    <li></li> </ul>

    <strong>For More Information on @XmlInverseReference</strong>

      <li></li> </ul>

      人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:Is it possible to use @XmlInverseReference where object and property are of same type?