5

How can I send JPA generated entities over an JAX WS web service without getting the an XML infinite cycle exception because of the cycle of references in those entities?

Any idea? I found this MOXy that can do it...partially. But i already have the entities generated and to manually add XmlTransient and such annotations to each of them it's crazy.

Do you have any other idea how to do it?

Thanks!

bdoughan
  • 147,609
  • 23
  • 300
  • 400
Andr
  • 617
  • 2
  • 9
  • 24

2 Answers2

1

make your getCustomer @XmlTransient

@XmlTransient

public Customer getCustomer() {

...

Community
  • 1
  • 1
1

EclipseLink JAXB (MOXy) can handle this with its bidirectional mapping with @XmlInverseReference:

import javax.persistence.*;

@Entity
public class Customer {

    @Id
    private long id;

    @OneToOne(mappedBy="customer", cascade={CascadeType.ALL})
    private Address address;

}

and

import javax.persistence.*;
import org.eclipse.persistence.oxm.annotations.*;

@Entity
public class Address implements Serializable {

    @Id
    private long id;

    @OneToOne
    @JoinColumn(name="ID")
    @MapsId
    @XmlInverseReference(mappedBy="address")
    private Customer customer;

}

For more information see:

You can also use MOXy's externalized representation of the metadata for this. For more information see:

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • dude. i know your blog. i read it it's quite cool. Thanks for help. But there is this problem: i'm dealing with many entities that are generated from database (like many tools can do it). How can i customize them so that they will generate @XmlInverseRefrence automatically? Thanks!:D – Andr Dec 08 '10 at 22:30