title: JPA2/Hibernate - Stop lazy loading?
body: <p>I'm having a problem where JPA is trying to lazily load my data when I don't want it to. Essentially what is happening is I'm using a Service to retrieve some data, and when I go to parse that data into JSON, the JSON library is triggering hibernate to try and lazily load the data. Is there any way to stop this? I've given an example below.</p>
  
  <pre><code>// Web Controller method
  public String getEmployeesByQuery(String query) {
  
      Gson gson = new Gson();
      List&lt;Employee&gt; employees = employeeService.findEmployeesByQuery(query);
  
      // Here is where the problem is occurring - the gson.toJSON() method is (I imagine)
      // using my getters to format the JSON output, which is triggering hibernate to
      // try and lazily load my data...
      return gson.toJSON(employees);
  }
  </code></pre>
  
  <p>Is it possible to set JPA/hibernate to not try and lazily load the data?</p>
  
  <p><strong>UPDATE:</strong> I realize that you can use FetchType.EAGER - but what if I don't want to eager load that data? I just want to stop hibernate from trying to retrieve more data - I already have the data I want. Right now whenever I try and access a get() method hibernate will throw a "no session or session is closed" error, which makes sense because my transaction was already committed from my service. </p>
  
  <p>Thanks!</p>