title: How is jackson serializing object outside of transition
body: <p>This is a bit bizarre for me.  My understanding is if you try to access entity outside of Hibernate session you should get an LazyInitializationException - no session, but I am not getting this exception.  In fact it seems like I still have session continue to my controller outside of my service layer which has @Transactional annotation.</p>
  
  <p><strong>Question</strong></p>
  
  <ul>
  <li>Is this the way it should be? or there is something I didn't set up correctly?</li>
  </ul>
  
  <p>Structure</p>
  
  <pre><code>       User
          | 
       Profile { hierarchies entity }
          |
    +-----+-----+
    |           |
  Teacher   Student
  </code></pre>
  
  <p>User</p>
  
  <pre><code>@Entity
  @Table(name="user")
  public class User {
  
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long id;
   private String firstname;
   private String lastname;
  
   @OneToMany(fetch = FetchType.LAZY , mappedBy = "user")
   @JsonManagedReference
   @JsonInclude(JsonInclude.Include.NON_EMPTY)
   private List&lt;Profile&gt; profiles = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>Service</p>
  
  <pre><code>@Override
  @Transactional
  public User getUserById(Long id) {
  
      Optional&lt;User&gt; optionalUser = userRepo.findById(id);
      User user = optionalUser.get();
  
      logger.info("\n User -&gt; {}", user);
      return user;
  }
  </code></pre>
  
  <p>Controller :: <strong>Instead of thow Exception, or should return empty array.  Hibernate perform a left join</strong></p>
  
  <pre><code>@GetMapping(value="/{userId}", produces=MediaType.APPLICATION_JSON_UTF8_VALUE)
  public User getUser(@PathVariable("userId") Long userId) {
  
      logger.info("User Controller is called");
  
      User user = userService.getUserById(userId);
  
      logger.info("User is returned -&gt; {}", user);
  
      logger.info("Profiles -&gt; {}", user.getProfiles());  // &lt;-- Expecting this to throw LazyInitializationException
  
      return user;
  }
  </code></pre>
  
  <p>Console</p>
  
  <pre><code>    018-05-31 15:17:35.462  INFO 15599 --- [nio-8080-exec-1] c.d.c.controller.UserController          : User Controller is called
  Hibernate: 
      select
          user0_.id as id1_4_0_,
          user0_.firstname as firstnam2_4_0_,
          user0_.lastname as lastname3_4_0_ 
      from
          user user0_ 
      where
          user0_.id=?
  2018-05-31 15:17:35.467  INFO 15599 --- [nio-8080-exec-1] c.d.c.services.UserServiceImpl           : 
   User -&gt; 
  User [id=1, firstname=Hendric, lastname=Rosenberg]
  2018-05-31 15:17:35.467  INFO 15599 --- [nio-8080-exec-1] c.d.c.controller.UserController          : User is returned -&gt; 
  User [id=1, firstname=Hendric, lastname=Rosenberg]
  Hibernate: 
      select
          profiles0_.user_id as user_id2_3_0_,
          profiles0_.id as id1_3_0_,
          profiles0_.id as id1_3_1_,
          profiles0_.user_id as user_id2_3_1_,
          profiles0_1_.citizent_id as citizent1_2_1_,
          profiles0_1_.profile_type as profile_2_2_1_,
          profiles0_2_.license as license1_1_1_,
          profiles0_2_.practitioner_type as practiti2_1_1_,
          profiles0_2_.profile_type as profile_3_1_1_,
          profiles0_2_.specialized as speciali4_1_1_,
          case 
              when profiles0_1_.id is not null then 1 
              when profiles0_2_.id is not null then 2 
              when profiles0_.id is not null then 0 
          end as clazz_1_ 
      from
          profile profiles0_ 
      left outer join
          patient profiles0_1_ 
              on profiles0_.id=profiles0_1_.id 
      left outer join
          medical_profession profiles0_2_ 
              on profiles0_.id=profiles0_2_.id 
      where
          profiles0_.user_id=?
  c.d.c.controller.UserController          : User is returned -&gt; [
   Student [profileType=STUDENT, id=A1236578889], 
   Teacher [profileType=TEACHER, license=234SFLLWEKD32342]]
  </code></pre>