title: Hibernate Object not detaching
body: <p>I have a User object that I pull from a hibernate session.  The User object has a Set of Car objects which I which I am retrieving and converting to JSON.  The problem is that when I return the Set to be converted to JSON it goes into an infinite loop of parsing it seems because the hibernate session is still active.</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>        public Set&lt;Car&gt; getUserCurrentCar(User user) {
                  user = (User) session.get(User.class, user.getId());
              Set&lt;Car&gt; retrievedCars = (Set&lt;Car&gt;) user.getCars();
              session.close();
              return retrievedCars;
          }
  </code></pre>
  
  <p>However, when I move the object values into an object without a session, everything parses fine without an error:</p>
  
  <pre><code>public Set&lt;Car&gt; getUserCurrentCar(User user) {
              user = (User) session.get(User.class, user.getId());
          Set&lt;Car&gt; Cars = new HashSet&lt;Car&gt;();
          Set&lt;Car&gt; retrievedCars = (Set&lt;Car&gt;) user.getCars();
  
          for(Car Car :retrievedCars){
          Car newCar = new Car();
          newCar.setTitle(car.getTitle());
          cars.add(newCar);
          }
          session.close();
          return cars;
      }
  </code></pre>
  
  <p>Though this works, I would like to modify my objects in the future and avoid all of this transferring of objects which seems repetitive.  </p>
  
  <p>Additionally, my Car object has a many-to-one back reference to User in hibernate mapping:</p>
  
  <pre><code>&lt;many-to-one name="user" 
      column="userId"
      not-null="true"/&gt;
  </code></pre>
  
  <p>How can I avoid this, and use a truly detached object to parse into JSON?</p>