title: How to use Hibernate4Module
body: <p>In an effort to avoid using <code>.size</code> to manually load fields, I would like to implement <code>Hibernate4Module</code>. unfortunately, being new at all things configurations, I can't seem to make it work. All I keep getting from java is: <code>Could not write content: could not initialize proxy - no Session</code>.</p>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = {"servlet.controller"})
  public class ServletConfig extends WebMvcConfigurerAdapter {
      ...
      @Override
      public void extendMessageConverters(List&lt;HttpMessageConverter&lt;?&gt;&gt; converters) {
          ObjectMapper mapper = null;
          for (HttpMessageConverter&lt;?&gt; converter : converters) {
              if (converter instanceof MappingJackson2HttpMessageConverter) {
                  mapper = ((MappingJackson2HttpMessageConverter) converter).getObjectMapper();
  
              }
          }
          if (mapper == null) {
              MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
              converter.setObjectMapper(mapper = new ObjectMapper());
              converters.add(converter);
          }
          Hibernate4Module hbm = new Hibernate4Module();
          hbm.enable(Feature.FORCE_LAZY_LOADING);
          mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
                 .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
          mapper.registerModule(hbm);
      }
      ...
  }
  </code></pre>
  
  <p>can anybody see what I'm doing wrong here?</p>
  
  <p><strong>NOTE</strong></p>
  
  <p>I have been running into some of the efficiency drawbacks, and I am looking into the fesablity of mitigating them outside of DTO's. I am very familiar with the DTO method, the software I am currently working on contains 60 files named "Ext*.java" (containing DTOs using Gson). Each of these is between 100 and 1000 lines long and increases the length of controller methods substantially. Additionally we are going to be trying to add more unit tests. Consequently I am desperate to find a way of eliminating as much DTO code as possible. That said, I am not at all opposed to using DTO's when they are needed, in fact I just finished my first <a href="http://www.baeldung.com/jackson-custom-serialization" rel="nofollow noreferrer">StdSerializer</a>. </p>
  
  <p>With a project being worked on by about 20 people across the continental united states, I am just hoping to be able to impose some order on the chaos.</p>