title: Hibernate search and JPA with JTA transaction
body: <p>I want to use the Hibernate Search full text search capabilities. I have a simple Java EE application. I annotated the entity classes and here is my persistence.xml:</p>
  
  <pre><code>&lt;persistence-unit name="library"&gt;
      &lt;jta-data-source&gt;jdbc/webrarydb&lt;/jta-data-source&gt;
      &lt;class&gt;net.hcpeter.webrary.entities.Author&lt;/class&gt;
      &lt;class&gt;net.hcpeter.webrary.entities.Book&lt;/class&gt;
      &lt;class&gt;net.hcpeter.webrary.entities.Request&lt;/class&gt;
      &lt;class&gt;net.hcpeter.webrary.entities.User&lt;/class&gt;
  
      &lt;properties&gt;
          &lt;property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/&gt;
          &lt;property name="hibernate.search.indexing_strategy" value="manual"/&gt;
          &lt;property name="hibernate.search.default.indexBase" value="/Users/hcpeter/Documents/workspace/indexes"/&gt;
          &lt;property name="hibernate.current_session_context_class" value="org.hibernate.context.JTASessionContext"/&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  </code></pre>
  
  <p>And I try to search this way:</p>
  
  <pre><code>EntityManager em = authorFacade.getEntityManager();
          FullTextEntityManager ftem = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
  
          ftem.getTransaction().begin();
          QueryBuilder qb = ftem.getSearchFactory().buildQueryBuilder().forEntity(Author.class).get();
          org.apache.lucene.search.Query query = qb.keyword().onFields("firsName", "lastName").matching("Author#1").createQuery();
  
          javax.persistence.Query persistenceQuery = ftem.createFullTextQuery(query, Author.class);
          List&lt;Author&gt; result = persistenceQuery.getResultList();
          em.getTransaction().commit();
          em.close();
          for (Author author : result) {
              System.out.println(author.getLastName() + " " + author.getFirstName());
          }
          return result;
  </code></pre>
  
  <p>Then I gave Cannot use an EntityTransaction while using JTA.
  So my question is how can I use hibernate Search with JTA?</p>