title: Hibernate - Table Locked after update
body: <p>I'm performing an update via a method using Hibernate and the EntityManager.</p>
  
  <p>This update method is called multiple times (within a loop).</p>
  
  <p>It seems like when I execute it the first time, it locks the table and does not free it.</p>
  
  <p>When trying to update the table via SQL Developer after having closed the application, I see the table is still locked because the update is hanging.</p>
  
  <p>What do you see as a solution to this problem? If you need more information, let me know.</p>
  
  <p><strong>Class</strong></p>
  
  <pre><code>@Repository
  @Transactional(propagation = REQUIRES_NEW)
  public class YirInfoRepository {
  
      @Autowired
      EntityManager entityManager;
  
      @Transactional(propagation = REQUIRES_NEW)
      public void setSent(String id) {
          String query = "UPDATE_QUERY";
          Query nativeQuery = entityManager.createNativeQuery(String.format(query, id));
          nativeQuery.executeUpdate();
      }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After having waited more than one hour, I launched the application again and it worked fine once but now again, it hangs.</p>
  
  <hr>
  
  <p><strong>UPDATE 2 -- I'll give a maximum bounty to whoever helps me solve this</strong></p>
  
  <p>On another place I use an application managed entity manager and it still gives me the same type of errors.</p>
  
  <pre><code>public void fillYirInfo() {
      File inputFile = new File("path");
      try (InputStream inputStream = new FileInputStream(inputFile);
           BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {
          bufferedReader.lines().skip(1).limit(20).forEach(line -&gt; {
              String[] data = line.split(",");
              String rnr = data[0];
              String linked = data[1];
              String email = data.length &gt; 2 ? data[2] : "";
  
  
  
      String insuredId = insuredPeopleRepository.getInsuredIdFromNationalId(rnr);
              int modifiedCounter = 0;
  
              if (!isNullOrEmpty(insuredId)) {
                  EntityManager entityManager = emf.createEntityManager();
                  EntityTransaction transaction = entityManager.getTransaction();
                  Query nativeQuery = entityManager.createNativeQuery(
                          "QUERY"
                  );
                  transaction.begin();
                  nativeQuery.executeUpdate();
                  entityManager.flush();
                  transaction.commit();
                  entityManager.close();
              }
  
              System.out.println(modifiedCounter + " rows modified");
          });
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>