title: JsonIdentityInfo use for hibernate mapping
body: <p>I have two entities City and Type and a many-to-many relationship between these two. What I need is: </p>
  
  <ol>
  <li>a json for City which contains the types</li>
  <li>a json for Type which contains the cities.</li>
  </ol>
  
  <p>I am using JsonIdentityInfo to stop the infinite recursion from mapping, but what I get from JSON doesn't really help me.
  This is what I currently get from the cities JSON</p>
  
  <pre><code>0:  {
       @idType: 1
       id: 1
       name: "destination"
       cities: [2]
             - 0:  {
                    @idCity: 2
                    id: 3
                    name: "Zalau"
                    description: "City...."
                    types: [2] &lt;---- I don't need this because I'm already in types JSON
                         - 0:  {
                                @idType: 3
                                id: 2
                                name: "other type"
                                cities: [1]
                                    - 0:  2
  
                            }
                          - 1:  1 &lt;----- end of don't need
                }
  
              - 1:  {
                     @idCity: 4
                     id: 0
                     name: "Cluj"
                     description: "City2..."
                     types: [1] &lt;---- don't need
                          - 0:  1
  
                 }
  
  }
  1:  3 &lt;----- I want to be the Type with id 3 although it was already generated from a city
  </code></pre>
  
  <p>But what I need is something like this:</p>
  
  <pre><code>0:  {
       @idType: 1
       id: 1
       name: "destination"
       cities: [2]
             - 0:  {
                    @idCity: 2
                    id: 3
                    name: "Zalau"
                    description: "City...."
                }
  
              - 1:  {
                     @idCity: 4
                     id: 0
                     name: "Cluj"
                     description: "City2..."
                 }
  
  }
  1:  {
       @idType: 3
       id: 2
       name: "other type"
       cities: [1]
          - 0:  {
                 @idCity: 2
                  id: 3
                  name: "Zalau"
                  description: "City...."
             }
  }
  </code></pre>
  
  <p>And the same thing for Cities JSON. I need it to be bidirectional.</p>
  
  <p>This is the code for my entities:</p>
  
  <p><strong>City:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "City")
  @XmlRootElement
  @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@idCity")
  
  public class City {
  
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     @Column(name = "idCity")
     private int id;
  
     @Column(name = "name")
     private String name;
  
     @Column(name = "description")
     private String description;
  
     @ManyToMany(fetch = FetchType.EAGER)
     @JoinTable(name = "CityType", joinColumns = { @JoinColumn(name = "idCity") }, inverseJoinColumns = {
          @JoinColumn(name = "idType") })
     private Set&lt;Type&gt; types = new HashSet&lt;Type&gt;();
  
  .... getters and setters
  }
  </code></pre>
  
  <p><strong>Type:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "Type")
  @XmlRootElement
  @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@idType")
  public class Type {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "idType")
      private int id;
  
      @Column(name = "name")
      private String name;
  
      @ManyToMany(fetch = FetchType.EAGER, mappedBy = "types")
      private Set&lt;City&gt; cities = new HashSet&lt;City&gt;();
  
      .... getters and setters
  }
  </code></pre>