title: Spring integration tests issue: could not initialize proxy - no Session through reference chain:
body: <p>I am trying to test a controller method and I have an issue that probably has to do with lazy loading and I am therefore trying to set up a open entity manager in view filter for my tests.</p>
  
  <p><strong>Setup method:</strong></p>
  
  <pre><code>@Before
  public void setup() {
      mockMvc = MockMvcBuilders.webAppContextSetup(wac)//
              .addFilters(springSecurityFilterChain, new OpenEntityManagerInViewFilter())//
              .defaultRequest(get("/").with(csrf())//
              .secure(true))//
              .build();//
  ...
  </code></pre>
  
  <p>Test method:</p>
  
  <pre><code>@Test
      public void shouldNotAllowAdvertisementModification() throws Exception {
          ChildminderAdvertisementInfo childminderAdvertisementInfo = new ChildminderAdvertisementInfo();
          childminderAdvertisementInfo.setAddressReference(VALID_ADDRESS_REFERENCE);
          ChildminderAdvertisement advertisement = helper.buildChildminderAdvertisement("balteo@yahoo.fr");
          childminderAdvertisementInfo.setAdvertisement(advertisement);
          CustomJacksonObjectMapper mapper = new CustomJacksonObjectMapper();
          String jsonChildminderAdvertisementInfo = mapper.writeValueAsString(childminderAdvertisementInfo);
          mockMvc.perform(post("/advertisement/childminder/edit/{advertisementId}", 1L).with(userDeatilsService("balteo@gmail.com"))//
                  .contentType(MediaType.APPLICATION_JSON)//
                  .header("X-Ajax", "true")//
                  .content(jsonChildminderAdvertisementInfo))//
                  .andDo(print())//
                  .andExpect(status().isForbidden());//
      }
  </code></pre>
  
  <p>Object Mapper:</p>
  
  <pre><code>public class CustomJacksonObjectMapper extends ObjectMapper {
  
      private static final long serialVersionUID = 1L;
  
      public CustomJacksonObjectMapper() {
          super();
          configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);//FIXME
          this.addMixInAnnotations(Curriculum.class, CurriculumMixin.class);
          this.addMixInAnnotations(Advertisement.class, AdvertisementMixin.class);
          this.addMixInAnnotations(Address.class, AddressMixin.class);
          this.addMixInAnnotations(Message.class, MessageMixin.class);
          this.addMixInAnnotations(Training.class, TrainingMixin.class);
          this.addMixInAnnotations(WorkExperience.class, WorkExperienceMixin.class);
      }
  
  }
  </code></pre>
  
  <p><strong>Exception stack trace:</strong></p>
  
  <pre><code>com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy - no Session (through reference chain: com.bignibou.controller.advertisement.ChildminderAdvertisementInfo["advertisement"]-&gt;com.bignibou.domain.ChildminderAdvertisement["address"]-&gt;com.bignibou.domain.Address_$$_jvst68_a["reference"])
      at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:232)
      at 
  </code></pre>
  
  <p>It seem the second filter is ignored by Spring Mvc Test and I still get the hibernate error... Can anyone please help?</p>