4 Replies Latest reply on Jul 14, 2011 5:09 AM by David Beaumont

    resteasy, jackson and LazyInitializationException

    David Beaumont Newbie

      Dear All,


      I have a JAX-RS & JPA application that worked fine under AS6 but now produces HTTP 500 errors when requesting JSON responses. I am trying to serialize the following class:









      public class Country implements Serializable {


          private static final long serialVersionUID = 4519728176152383566L;


          private Integer id;

          private Country parent;

          private String name;







          public Integer getId() {return id;}

          public void setId(Integer id) {this.id = id;}






          public Country getParent() {return parent;}

          public void setParent(Country parent) {this.parent = parent;}





          public String getName() {return name;}

          public void setName(String name) {this.name = name;}




      The @Json annotations forced jackson to only include the correct properties. Under AS7, these annotations no longer seem to be having any effect, resulting in:


      org.codehaus.jackson.map.JsonMappingException caused by ... org.hibernate.LazyInitializationException


      This happens because jackson tries to serialize the 'parent' property of the Country class, which has not been eagerly fetched by the JPA query. I have tried several variations of the annotations but cannot find anything that works. Does anyone know the correct mix?