title: JPA: Native Queries does not trigger execution of cached inserts/updates in same transaction
body: <p>I have a JUnit Test where I set up the test data in the beginning of the test case, and then test for the conditions of the test case afterward in the same test method. The query that tests the conditions of the test case is a native query. I know that I have to explicitly call EntityManager.flush() in order for my inserts/updates to be written immediately to the DB since they are in the same transaction. Additionally, I noticed that I can replace entityManager.flush() with a JPA query, which seems to achieve the same thing. I have heard that JPA will cache DB operations in the same transaction until there is a need to execute them immediately, such as when select queries are issued. So this all makes sense. My question is, why doesn't this behavior also apply to native queries? Here my native query does not trigger the immediate execution of insert/updates in testSetup(), thus causing my assert to fail.</p>
  
  <pre><code>@Test
  @Transactional
  public void testCase() {
      testSetup();
      entityManager.flush();  // can be replaced with entityManager.createQuery("from Person");
  
      List resultList = entityManager.createNativeQuery("select * from Person").getResultList();
      Assert.assertTrue(resultList.size() == 1);
  }
  </code></pre>