title: Using Jackson 2.2 to serialize Hibernate result into JSON string, infinite loop
body: <p>I have a bi-directional relationship between 2 objects - EvalMasterEvaluation (one) and EvalMasterEvalDetail (many). I've tried a number of different solutions, but I must be implementing them wrong. My goal is to return a list of details for a given eval id.</p>
  
  <p>I'm using Jackson 2.2 (with databind and datatype-hibernate3 libs), hibernate 3.6 and spring 3.2.1. Some code omitted to make this easier to read.</p>
  
  <p>The parent class:</p>
  
  <pre><code>@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
  @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
  public class EvalMasterEvaluation implements java.io.Serializable {
  
      private BigDecimal id;
      @JsonManagedReference private Set&lt;EvalMasterEvalDetail&gt; evalMasterEvalDetails = new HashSet&lt;EvalMasterEvalDetail&gt;(
              0);
  }
  </code></pre>
  
  <p>The child class:</p>
  
  <pre><code>@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
  @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id")
  public class EvalMasterEvalDetail implements java.io.Serializable {
      private BigDecimal id;
      @JsonBackReference private EvalMasterEvaluation evalMasterEvaluation;
      private String active;
  }
  </code></pre>
  
  <p>My Hibernate Criteria query:</p>
  
  <pre><code>Criteria criteria = session.createCriteria(EvalMasterEvalDetail.class)
                      .add(Restrictions.eq("active", "Y"))
                      .setFetchMode("evalMasterEvaluation", FetchMode.JOIN)
                      .createAlias("evalMasterEvaluation", "eval")
                      .add(Restrictions.eq("eval.id", evalId))
                      .addOrder(Order.asc("detailOrder"));
  
              details = criteria.list();
  
              ObjectMapper mapper = new ObjectMapper();
              json = mapper.writeValueAsString(details);
  </code></pre>
  
  <p>EvalMasterEvaluation mapping</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="org.anes.surveys.domain.EvalMasterEvaluation" table="EVAL_MASTER_EVALUATION"&gt;
          &lt;id name="id" type="big_decimal"&gt;
              &lt;column name="ID" precision="22" scale="0" /&gt;
              &lt;generator class="sequence-identity" &gt;
                  &lt;param name="sequence"&gt;EVAL_MASTER_EVALUATION_SEQ&lt;/param&gt;
              &lt;/generator&gt;
          &lt;/id&gt;
          &lt;set name="evalMasterEvalDetails" table="EVAL_MASTER_EVAL_DETAIL" inverse="true" lazy="true" fetch="select"&gt;
              &lt;key&gt;
                  &lt;column name="MASTER_EVAL_ID" precision="22" scale="0" not-null="true" /&gt;
              &lt;/key&gt;
              &lt;one-to-many class="org.anes.surveys.domain.EvalMasterEvalDetail" /&gt;
          &lt;/set&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>EvalMasterEvalDetail mapping</p>
  
  <pre><code>&lt;hibernate-mapping&gt;
      &lt;class name="org.anes.surveys.domain.EvalMasterEvalDetail" table="EVAL_MASTER_EVAL_DETAIL"&gt;
          &lt;id name="id" type="big_decimal"&gt;
              &lt;column name="ID" precision="22" scale="0" /&gt;
              &lt;generator class="sequence-identity" &gt;
                  &lt;param name="sequence"&gt;EVAL_MASTER_EVAL_DETAIL_SEQ&lt;/param&gt;
              &lt;/generator&gt;
          &lt;/id&gt;
          &lt;many-to-one name="evalMasterEvaluation" class="org.anes.surveys.domain.EvalMasterEvaluation" fetch="select"&gt;
              &lt;column name="MASTER_EVAL_ID" precision="22" scale="0" not-null="true" /&gt;
          &lt;/many-to-one&gt;
          &lt;property name="active" type="string"&gt;
              &lt;column name="ACTIVE" length="1" not-null="true" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>