title: Lock obtain timed out error : NativeFSLock@C:\lucene\indexes\com.srccodes.example.hibernate.Contact\write.lock
body: <p>I have a requirement to integrate elastic search Engine for SQLite database. So, am using Hibernate Search for the search engine integration. After i have a new record into the table am getting the error.</p>
  
  <p>Am getting the below error : </p>
  
  <p>ERROR: HSEARCH000058: Exception occurred org.apache.lucene.store.LockObtainFailedException: Lock obtain timed out: NativeFSLock@C:\lucene\indexes\com.srccodes.example.hibernate.Contact\write.lock
  Primary Failure:
      Entity com.srccodes.example.hibernate.Contact  Id null  Work Type  org.hibernate.search.backend.PurgeAllLuceneWork</p>
  
  <p>Please find my code below: </p>
  
  <pre><code>public class App {
  
  private static void doIndex() throws InterruptedException {
      Session session = HibernateUtil.getSession();
  
      FullTextSession fullTextSession = Search.getFullTextSession(session);
      fullTextSession.createIndexer().startAndWait();
  
      fullTextSession.close();
  }
  
  private static List&lt;Contact&gt; search(String queryString) {
      Session session = HibernateUtil.getSession();
      FullTextSession fullTextSession = Search.getFullTextSession(session);
  
      QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Contact.class).get();
      org.apache.lucene.search.Query luceneQuery = queryBuilder.keyword().onFields("name").matching(queryString).createQuery();
  
      // wrap Lucene query in a javax.persistence.Query
      org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery(luceneQuery, Contact.class);
  
      List&lt;Contact&gt; contactList = fullTextQuery.list();
  
      fullTextSession.close();
  
      return contactList;
  }
  
  private static void displayContactTableData() {
      Session session = null;
  
      try {
          session = HibernateUtil.getSession();
  
          // Fetching saved data
          List&lt;Contact&gt; contactList = session.createQuery("from Contact").list();
  
          for (Contact contact : contactList) {
              System.out.println(contact);
          }
  
      } catch (Exception ex) {
          ex.printStackTrace();
      } finally{
          if(session != null) {
              session.close();
          }
      }
  }
  
  public static void main(String[] args) throws InterruptedException {
      System.out.println("\n\n******Data stored in Contact table******\n");
      displayContactTableData();
  
      // Create an initial Lucene index for the data already present in the database
      doIndex();
  
      Scanner scanner = new Scanner(System.in);
      String consoleInput = null;
  
      while (true) {
          // Prompt the user to enter query string
          System.out.println("\n\nEnter search key (To exit type 'X')");      
          System.out.println();
          consoleInput = scanner.nextLine();
  
          if("X".equalsIgnoreCase(consoleInput)) {
              System.out.println("End");
              System.exit(0);
          }   
  
          List&lt;Contact&gt; result = search(consoleInput);            
          System.out.println("\n\n&gt;&gt;&gt;&gt;&gt;&gt;Record found for '" + consoleInput + "'");
  
          for (Contact contact : result) {
              System.out.println(contact);
          }               
      }           
  }
  </code></pre>
  
  <p>}</p>
  
  <p>My Dependencies :</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;!-- hibernate --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;4.1.4.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-search&lt;/artifactId&gt;
          &lt;version&gt;4.1.1.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- SQLite JDBC library --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.xerial&lt;/groupId&gt;
          &lt;artifactId&gt;sqlite-jdbc&lt;/artifactId&gt;
          &lt;version&gt;3.7.2&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>