title: CreateQuery is not valid without active transaction
body: <p>I'm trying to use the Spring @Transactional annotation, but i have problems when the method <em>findAll</em> is called and i have this error:</p>
  
  <pre><code>  org.hibernate.HibernateException: createQuery is not valid without active transaction
    at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:352)
    at com.sun.proxy.$Proxy57.createQuery(Unknown Source)
    at org.munaycoop.taskmanager.daos.PersonDataAccesObject.findAll(PersonDataAccesObject.java:20)
    at org.munaycoop.taskmanager.services.PersonService.findAll(PersonService.java:26)
    at org.munaycoop.taskmanager.controllers.PersonController.ShowAllPersons(PersonController.java:20)
    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:215)
    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:781)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:390)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:440)
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:926)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
  </code></pre>
  
  <p>the Person DAO:</p>
  
  <pre><code>@Repository
  @Transactional
  public class PersonDataAccesObject implements IPersonDataAccesObject {
  
      @Autowired
      private SessionFactory session;
  
      @Override
      public List findAll() {
          return session.getCurrentSession().createQuery("from persons").list();
      }
  </code></pre>
  
  <p>and this is my <code>servlet-context.xml</code>:</p>
  
  <p>
      </p>
  
  <pre><code>&lt;!-- Enables the Spring MVC @Controller programming model --&gt;
  &lt;annotation-driven /&gt;
  
  &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --&gt;
  &lt;resources mapping="/resources/**" location="/resources/bootstrap/" /&gt;
  
  &lt;!-- Database Configuration --&gt;
  &lt;context:property-placeholder location="classpath:database.properties" /&gt;
  
  &lt;beans:bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;beans:property name="driverClassName" value="${jdbc.driverClassName}" /&gt;
      &lt;beans:property name="url" value="${jdbc.databaseUrl}" /&gt;
      &lt;beans:property name="username" value="${jdbc.username}" /&gt;
      &lt;beans:property name="password" value="${jdbc.password}" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;!-- Hibernate session factory --&gt;
  &lt;beans:bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;beans:property name="dataSource" ref="dataSource"/&gt;
  
      &lt;beans:property name="hibernateProperties"&gt;
          &lt;beans:props&gt;
              &lt;beans:prop key="hibernate.connection.pool_size"&gt;${hibernate.pool_size}&lt;/beans:prop&gt;
              &lt;beans:prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/beans:prop&gt;
              &lt;beans:prop key="hibernate.current_session_context_class"&gt;${hibernate.current_session}&lt;/beans:prop&gt;
              &lt;beans:prop key="hibernate.cache.provider_class"&gt;${hibernate.provider_class}&lt;/beans:prop&gt;
              &lt;beans:prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/beans:prop&gt;
              &lt;beans:prop key="hibernate.hbm2ddl.auto"&gt;${hibernate.hbm2ddl}&lt;/beans:prop&gt;
          &lt;/beans:props&gt;
      &lt;/beans:property&gt;
  
      &lt;beans:property name="mappingResources"&gt;
          &lt;beans:list&gt;
              &lt;beans:value&gt;hibernate.cfg.xml&lt;/beans:value&gt;
          &lt;/beans:list&gt;
      &lt;/beans:property&gt;
  &lt;/beans:bean&gt;
  
  &lt;!-- Hibernate TransactionManager --&gt;
  &lt;beans:bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
      &lt;beans:property name="sessionFactory" ref="sessionFactory"/&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p>I tried removing this line <code>&lt;beans:prop key="hibernate.current_session_context_class"&gt;${hibernate.current_session}&lt;/beans:prop&gt;</code>, but another error has came, why this is not working? </p>