title: Hibernate Search with Jpa 2 and lucene java.lang.ClassNotFoundException
body: <p>I am writing an application where i am trying to make an example on hibernate search with Lucene.
  In my database, i got an array named A_ROLE witch contains an <strong>ID</strong> field and a <strong>NAME</strong> field. Into this array i have store the data bellow:</p>
  
  <ol>
  <li>1 - Agalloh</li>
  <li>2 - Rorry Galaher</li>
  <li>3 - Isis Isis</li>
  </ol>
  
  <p>My entity class looks like this:</p>
  
  <pre><code>@Entity
  @Table(name="A_ROLE")
  @NamedQuery(name="ARole.findAll", query="SELECT a FROM ARole a")
  @Indexed
  public class ARole implements Serializable {
  private static final long serialVersionUID = 1L;
  
  @Id
      @DocumentId
  @SequenceGenerator(name="A_ROLE_ID_GENERATOR", sequenceName="A_ROLE_SEQ")
  @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="A_ROLE_ID_GENERATOR")
  @Column(unique=true, nullable=false, precision=38)
      @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
      //@NumericField
  private long id;
  
  @Column(length=50)
      @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
  private String name;
  
  //bi-directional many-to-many association to APermission
  @ManyToMany
  @JoinTable(
      name="A_ROLE_PERMISSION"
      , joinColumns={
          @JoinColumn(name="ROLE_ID", nullable=false)
          }
      , inverseJoinColumns={
          @JoinColumn(name="PERMISSION_ID", nullable=false)
          }
      )
  private List&lt;APermission&gt; APermissions;
  
  //bi-directional many-to-many association to AUser
  @ManyToMany(mappedBy="ARoles")
  private List&lt;AUser&gt; AUsers;
  
      constructor, getters and setters
  </code></pre>
  
  <p>and i have create an interface named DataBaseExchanges which contains a method lucinExample(). This method is responsible for the hibernate search and its implementation is being from the class bellow </p>
  
  <pre><code>import ec.ep.europarl.appdif.db.entity.ARole;
  import ec.ep.europarl.appdif.service.DataBaseExchanges;
  import java.util.List;
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import org.hibernate.search.jpa.FullTextEntityManager;
  import org.hibernate.search.query.dsl.QueryBuilder;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  @Service("dataSearch")
  public class DataBaseExchangesImpl implements DataBaseExchanges {
  
  @PersistenceContext
  public EntityManager em;
  
  @Override
  @Transactional
  public void lucinExample() {
      FullTextEntityManager fullTextEntityManager =
     org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
      //em.getTransaction().begin();
  
      QueryBuilder qb = 
      fullTextEntityManager.getSearchFactory().buildQueryBuilder()
      .forEntity(ARole.class).get();
      org.apache.lucene.search.Query query = qb
              .keyword()
              .onFields("name")
              .matching("agalloh")
              .createQuery();
  
      // wrap Lucene query in a javax.persistence.Query
      org.hibernate.search.jpa.FullTextQuery persistenceQuery =
      fullTextEntityManager.createFullTextQuery(query, ARole.class);
  
      // execute search
      List result = persistenceQuery.getResultList();
  
      em.close();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>i call this method from a controller, where i have @Autowird the above mentioned interface.</p>
  
  <p>When i debug the above functionality it stops at this line of the implementation code:</p>
  
  <pre><code>org.hibernate.search.jpa.FullTextQuery persistenceQuery =
      fullTextEntityManager.createFullTextQuery(query, ARole.class);
  </code></pre>
  
  <p>with error report:</p>
  
  <pre><code>SEVERE: Servlet.service() for servlet [appdif] in context with path [] threw exception   
  [Handler processing failed; nested exception is java.lang.NoClassDefFoundError:  
  org/hibernate/BasicQueryContract] with root cause
  java.lang.ClassNotFoundException: org.hibernate.BasicQueryContract
  at   
  org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
  at
  org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
  at 
  org.hibernate.search.impl.FullTextSessionImpl.createFullTextQuery
  (FullTextSessionImpl.java:81)
  at
  org.hibernate.search.jpa.impl.FullTextEntityManagerImpl.
  createFullTextQuery(FullTextEntityManagerImpl.java:112)
  at
  ec.ep.europarl.appdif.service.impl.DataBaseExchangesImpl.
  lucinExample(DataBaseExchangesImpl.java:43)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.
  invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.springframework.aop.support.AopUtils.
  invokeJoinpointUsingReflection(AopUtils.java:317)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
  at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
  at com.sun.proxy.$Proxy102.lucinExample(Unknown Source)
  at ec.ep.europarl.appdif.web.controllers.HomeController.home(HomeController.java:27)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
  at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:744)
  </code></pre>
  
  <p>I can't figure out what the problem is, at my maven dependencies i have include hibernate search 4.5.0.Final.
  Please can anyone help on this?</p>