Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-842

Spring: Could not write content: could not initialize proxy - no Session

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 2016.12.0
    • Fix Version/s: 2018.1.0
    • Component/s: examples
    • Labels:
      None

      Description

      In the Spring Wildfly Swarm example, a call

      curl -X GET http://localhost:8080/employee/2
      

      would cause following exception to occur:

      2016-11-16 14:05:39,995 WARN  [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-1) Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: could not initialize proxy - no Session (through reference chain: org.wildfly.swarm.examples.springdata.model.Employee_$$_jvst7d_0["id"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy - no Session (through reference chain: org.wildfly.swarm.examples.springdata.model.Employee_$$_jvst7d_0["id"])
      
      

      The implementation of the Spring Data repository returns a JavassistLazyInitializer with all it's values set to null. Values will not be loaded outside the running transaction and thus the Jackson serializer throws an exception while trying to convert the object to JSON.

      The solution can be found by using

      employeeRepository.findOne(id) 
      

      instead of

      employeeRepository.getOne(id)
      

      Patch in attachment fixes the EmployeeService in the Spring-Data module.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                pw999 Phillip W
                Reporter:
                pw999 Phillip W
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: