title: Lazy attribute is null inside transaction after creation
body: <p>I have a small example with some get/post mappings and JpaRepository calls in Spring Boot.</p>
  
  <p>Firstly I have two entity Classes:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = "stock")
  public class Stock extends BaseEntity
  {
      @Column(name = "value")
      public String value;
  
      public String getValue() {
          return value;
      }
  
      public void setValue(String value) {
          this.value = value;
      }
  }
  
  @Entity
  @Table(name = "stock_item")
  public class StockItem extends BaseEntity
  {
  
      @ManyToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "stock_id", insertable = false, updatable = false)
      public Stock stock;
  
      @Column(name = "stock_id")
      public Long stockId;
  
      @Column(name = "value")
      public String value;
  }
  </code></pre>
  
  <p>I have a many-to-one association from <code>StockItem</code> to <code>Stock</code>. 
  I insert a <code>Stock</code> and have a controller as below:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Autowired
  public Controller(StockItemRepository stockItemRepository) {
      this.stockItemRepository = stockItemRepository;
  }
  
  @RequestMapping("/")
  @Transactional(readOnly = true)
  public String get() {
  
      List&lt;StockItem&gt; stockItemList = stockItemRepository.getItemsById(1L);
      System.out.println("TX MANAGER: " + TransactionSynchronizationManager.isActualTransactionActive());
  
      for (StockItem stockItem : stockItemList) {
          System.out.println(stockItem.getStock().getValue());
      }
  
  
      return "get";
  }
  
  @RequestMapping("/fromSave")
  @Transactional
  public String post() {
      StockItem stockItem = new StockItem();
      stockItem.setStockId(1L);
      stockItemRepository.saveAndFlush(stockItem);
  
      System.out.println("saveCalled");
  
      return get();
  }
  </code></pre>
  
  <p>and <code>getItemsById</code> in the repository is defined as follows:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Query("FROM StockItem si " +
          "JOIN FETCH si.stock stk " +
          "WHERE si.stockId = :id")
  List&lt;StockItem&gt; getItemsById(@Param("id") Long id);
  </code></pre>
  
  <p>From my understanding, when I call the post method:</p>
  
  <ul>
  <li>it creates a new item</li>
  <li>sets the id of the associated attribute</li>
  <li>saves and ends the transaction</li>
  </ul>
  
  <p>Heres where things get strange...
  I call get after the post and make the above repository call, which has a join fetch and when I call <code>stockitem.getStock().getValue()</code> I get a null pointer when I expect a <code>LazyInitializationException</code>.</p>
  
  <p>If I call the <code>get()</code> from the mapping, outside the class, it successfully loads the associated object.</p>
  
  <p>I have even removed the <code>@Transaction</code> annotation from the get, as well as 
  the join-fetch from my query and again, if I call from outside of the class it works and from the post, it crashes with a <code>NullPointerException</code>.</p>
  
  <p>I have put the <code>get</code> inside of a <code>TransactionTemplate.execute()</code> and I still get a <code>NullPointerException</code> when calling from inside the class. </p>
  
  <p>So the main questions are: </p>
  
  <ul>
  <li>Why am I getting a <code>NullPointerException</code> instead of <code>LazyInitializationException</code>? </li>
  <li>What is the transaction magic behind having no transaction but successfully fetching a lazy attribute??</li>
  </ul>