title: Create an database entity in one thread and try to retrieve the same entity in another thread gives different result
body: <p>I am trying to create a scenario where I create an entity in main thread and then use another thread to query the same entity that was just created. However, if I execute the query to fetch the entity outside of the thread, it returns value. However, if I query it inside the thread, I get <code>null</code>. I have attached the source code with comments and tried to make it simple. I would appreciate if anyone can help me point out the issue. I am using <code>JPA</code> and <code>Spring framework</code>. For database, I am using <code>postgresql</code>. Thank you. Here is the sample program:</p>
  
  <pre><code>    @Test
      public void test() {
          Employee generatedEmployee = employeeService.createEmployee(passEmployeeInfo()); // CREATE TEST EMPLOYEE.. passEmployeeInfo() just sets name, phone etc.
          System.out.println(generatedEmployee.getReferenceId()); //Output is: 20
  
          generatedEmployee.setReferenceId(30L); //update the referenceId here...
          long refId = generatedEmployee.getReferenceId();
  
          Employee employeeFromDB = employeeQuery.getEmployeeByReferenceId(refId); //Use refId to get Employee from table
          System.out.println(employeeFromDB);  //Output is:  Employee [id=2, refId=30, ...]
  
          Thread thread = new Thread(new Runnable() {
              @Override
              public void run() {
                  Employee employee = employeeQuery.getEmployeeByReferenceId(refId);
                  System.out.println("The employee inside run method is: " + employee); //Output is NULL here.. This is what I am trying to understand.
              }
          });
          thread.start();
  }
  </code></pre>