title: Error in Hibernate FullTextSession
body: <p>I have prepared a Spring MVC application, where I use Hibernate Search, alongwith </p>
  
  <p>the CRUD operations.</p>
  
  <p>The CRUD operations are working fine, but when I apply Hibernate Search,</p>
  
  <pre><code> it gives me an error : HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: HSEARCH000178: Unable to create a FullTextSession from a null Session
  </code></pre>
  
  <p>I have used the FullTextSession Class</p>
  
  <p>My Code :</p>
  
  <p>////////////////////////Controller///////////////////</p>
  
  <pre><code>@RequestMapping("/search")
      public ModelAndView search(String query, Model model,HttpServletRequest req) throws InterruptedException
      {
          String name = req.getParameter("name");
          String address = req.getParameter("address");
          String salary = req.getParameter("salary");
          String gender = req.getParameter("gender");
          model.addAttribute("name", name);
          model.addAttribute("address", address);
          model.addAttribute("salary", salary);
          model.addAttribute("gender", gender);
          List&lt;Person&gt; searchResults = null;
      searchResults = ps.search(query);
          model.addAttribute("searchResults", searchResults);
          return new ModelAndView("search");
      }
  </code></pre>
  
  <p>//////////////////////DAOImplementation////////////</p>
  
  <pre><code>@SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
  public List&lt;Person&gt; search(String text) throws InterruptedException{
  
       fullTextSession = Search.getFullTextSession(session);
      try {
          Transaction tx = fullTextSession.beginTransaction();
          org.hibernate.search.query.dsl.QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Person.class ).get();
          org.apache.lucene.search.Query query = qb.keyword().onFields("name", "address", "salary","gender").matching(text).createQuery();
          org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(query, Person.class);
           List result = hibQuery.list();
           Iterator&lt;Person&gt; it = result.iterator();
           while (it.hasNext()) {
                 Person p = (Person) it.next();
                 System.out.println(p);
                }
                tx.commit();
  
      }
      finally{
          session.close();
      }
  
  
  return null;
  }
  </code></pre>
  
  <p>//////////////////////search.jsp///////////</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
      &lt;%@ taglib uri="http://www.springframework.org/tags/form"
      prefix="springForm"%&gt;
       &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html xmlns:th="http://www.thymeleaf.org"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Search Page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
    &lt;ol&gt;
      &lt;li th:each="person : ${searchResults}"&gt;
        &lt;b&gt;&lt;span th:text="${person.name}"&gt;&lt;/span&gt;&lt;/b&gt; - 
        &lt;span th:text="${person.address}"&gt;&lt;/span&gt; -
        &lt;span th:text="${person.salary}"&gt;&lt;/span&gt;
        &lt;span th:text="${person.gender}"&gt;&lt;/span&gt;
      &lt;/li&gt;
    &lt;/ol&gt;
    &lt;springForm:form action="/MainAssignment3/search" method="GET"
          commandName="person"&gt;
      &lt;tr&gt;
                  &lt;td&gt;Enter Search Text:&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="text"&gt;
                  &lt;input type="submit" value="submit" onclick="/MainAssignment3/search"&gt;&lt;/input&gt;              &lt;/td&gt;
  
  
  
              &lt;/tr&gt;
          &lt;/springForm:form&gt;
    &lt;table border="1"&gt;
  &lt;tr&gt;
      &lt;th&gt;id&lt;/th&gt;
      &lt;td&gt;name&lt;springForm:errors path='${person.name}' /&gt;&lt;/td&gt;    
          &lt;td&gt;address&lt;springForm:errors path='${person.address}' /&gt;&lt;/td&gt;
      &lt;td&gt;gender&lt;springForm:errors path='${person.gender}' /&gt;&lt;/td&gt;        
  
      &lt;td&gt;salary&lt;springForm:errors path='${person.salary}' /&gt;&lt;/td&gt;&lt;/tr&gt;   
   &lt;c:forEach var="p" items='${searchResults}' varStatus="status"&gt;
      &lt;tr&gt;
  
          &lt;td&gt;${p.id}&lt;/td&gt;
          &lt;td&gt;${p.name}&lt;/td&gt;
          &lt;td&gt;${p.address}&lt;/td&gt;
          &lt;td&gt;${p.gender}&lt;/td&gt;
          &lt;td&gt;${p.salary}&lt;/td&gt;
  
      &lt;/tr&gt;
  
  &lt;/c:forEach&gt; 
  
  
  &lt;/table&gt;
  
    &lt;p th:if="${searchResults.isEmpty()}"&gt;
      &lt;strong&gt;Hint&lt;/strong&gt;: the query "&lt;a href='/search?query=any'&gt;any&lt;/a&gt;" 
      should return some results.
    &lt;/p&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>/////////////////////////////stacktrace////////////////</p>
  
  <pre><code>java.lang.IllegalArgumentException: HSEARCH000178: Unable to create a FullTextSession from a null Session
      org.hibernate.search.Search.getFullTextSession(Search.java:38)
      com.dao.PersonDAOImpl.search(PersonDAOImpl.java:116)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:498)
      org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
      org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:280)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
      com.sun.proxy.$Proxy39.search(Unknown Source)
      com.service.PersonServiceImpl.search(PersonServiceImpl.java:45)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:498)
      org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      com.sun.proxy.$Proxy41.search(Unknown Source)
      com.controller.MainController.search(MainController.java:66)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:498)
      org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>