title: Hibernate search lucene consuming database connections
body: <p>I have configured maxPoolSize 10 for c3p0 pooling. minPoolSize is 3.
  Whenever i start my server and execute show processlist for mysql database, there are three connections established. This will be remain three only unless there is huge traffic to the server. This is fine.</p>
  
  <p>I have implemented search functionality which starts indexing for the first time.
  When application does search and when i check show processlist for my database , all the db connections are open now. I see all the 10 connections are open.
  Is it the accepted behavior. Ideally i would say utilizing opening 2 or 3 connections could have been fine.
  Why hibernate lucene is utilizing many connections?
  Can I configure the max connections somewhere for lucene.</p>
  
  <p>I am posting my code below. </p>
  
  <pre><code>fullTextEntityManager.createIndexer().startAndWait(); 
  </code></pre>
  
  <p>will execute only one time for the application</p>
  
  <pre><code>    @Transactional
  public List&lt;E&gt; searchRecord(String searchText) {
  
      FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
  
      if (CREATE_INDEX.equals("START")) {
          try {
              log.info("creating indexes");
              fullTextEntityManager.createIndexer().startAndWait();
              CREATE_INDEX = "END";
          } catch (InterruptedException e) {
              log.info("error in creating indexes", e);
          }
      }
      log.info("lucene query builder");
      QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(getEntityClass())
              .get();
      // org.apache.lucene.search.Query luceneQuery =
      // qb.keyword().onFields("name")
      // .matching(searchText).createQuery();
      if(searchText.contains(" ")){
          String[] splittedText = searchText.split(" ");
          searchText = splittedText[0];
      }
      org.apache.lucene.search.Query luceneQuery = qb.keyword().wildcard().onField(getSearchField())
              .matching(searchText.toLowerCase() + '*').createQuery();
  
      javax.persistence.Query jpaQuery = fullTextEntityManager.createFullTextQuery(luceneQuery, getEntityClass());
  
      List&lt;E&gt; result = jpaQuery.getResultList();
      return result;
  }
  </code></pre>