title: The easiest way to remove the bidirectional recursive relationships?
body: <p>I use the <a href="http://code.google.com/p/google-gson/" rel="noreferrer">Gson</a>  library to convert Java objects to a Json response...
  the problem is that after a JPA requests the object retrieved from DB can not be converted because of a recursive relationship with other entities(<a href="https://stackoverflow.com/questions/10027268/how-to-serialize-a-java-util-liste-to-json-using-gson-library">see my previous question</a>) for example :</p>
  
  <pre><code>public class Gps implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @Basic(optional = false)
      @Column(name = "IMEI", nullable = false, length = 20)
      private String imei;
      //some code here...
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "gpsImei", fetch = FetchType.LAZY)
      private List&lt;Coordonnees&gt; coordonneesList;
  
  
  public class Coordonnees implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "IDCOORDONNEES", nullable = false)
      private Integer idcoordonnees;
      //some code here...
      @JoinColumn(name = "GPS_IMEI", referencedColumnName = "IMEI", nullable = false)
      @ManyToOne(optional = false, fetch = FetchType.LAZY)
      private Gps gpsImei;
  </code></pre>
  
  <p>My source code:</p>
  
  <pre><code>  EntityManagerFactory emf=Persistence.createEntityManagerFactory("JavaApplication21PU");
    GpsJpaController gjc=new GpsJpaController(emf);
  
    Gps gps=gjc.findGps("123456789012345");
  
    for(int i=0;i&lt;gps.getCoordonneesList().size();i++){
     gps.getCoordonneesList().get(i).setGpsImei(null);
    }  
  
    Gson gson=new Gson();
    String json=gson.toJson(gps);//convert to json response
  
    System.out.println(json);  
  </code></pre>
  
  <p>As you can see here i made :</p>
  
  <pre><code>   for(int i=0;i&lt;gps.getCoordonneesList().size();i++){
       gps.getCoordonneesList().get(i).setGpsImei(null);
     }  
  </code></pre>
  
  <p>only to kill the recursive relationship by setting null for each GPS object in the coordonneesList..</p>
  
  <p>In your opinion this is a good solution or is there another method more practical?
  Thanks</p>