title: Java Hibernate Entities not joined correctly (bidirectional)
body: <p>I have two <code>Java</code> <code>Hibernate</code> entities with <code>oneToMany</code> relation. Also I have <code>Spring</code> controller and <code>AngularJS</code> on front-end. When I try <code>/cars/getCars</code> on <code>Chrome</code> browser, I get network status failed. And Eclipse stop work (freeze).</p>
  
  <pre><code>@Entity
  @Table(name="auto")
  public class Make {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
  
    @Column(length = 100)
    private String make;
  
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "make")
    private List&lt;Model&gt; models = new ArrayList&lt;Model&gt;(0);
  
    public String getMake() {
      return make;
    }
  
    ...
  
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>@Entity
  @Table(name="models")
  public class Model {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;
  
    @Column(length = 100)
    private String model;
  
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "fk_maker") 
    private Make make;
  
    public Model() {}
  
    public void setModel(String model){
      this.model = model;
    }
    ...
  </code></pre>
  
  <p>DAO </p>
  
  <pre><code>public List&lt;Make&gt; getCars(){
      Criteria criteria = session.createCriteria(Make.class);
      return criteria.list();
  }   
  </code></pre>
  
  <p>and <code>Spring</code> controller:</p>
  
  <pre><code>@RequestMapping("/cars/getCars")
   public @ResponseBody List&lt;Make&gt; getCars(){
       DAO d = new DAO();
       return d.getCars();
   }
  </code></pre>
  
  <p>For me looks like n+1 query problem.</p>
  
  <p>And fragment from exception :</p>
  
  <pre><code>..at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157)
  at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:149)
  at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:111)
  at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:24)
  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:656)
  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675)
  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157)
  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:656)
  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675)
  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157)
  at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:149)
  at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:111)
  at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:24)
  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:656)
  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675)
  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157)
  at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:656)
  at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675)
  at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157) ...
  </code></pre>
  
  <p>And if change : <code>@OneToMany(fetch = FetchType.LAZY, mappedBy = "make") to @OneToMany</code> an remove <code>make</code> field from <code>Model</code> class than start work normal but now I cant get <code>make</code> by <code>model</code>.</p>