title: Hibernate SessionFactory through Spring
body: <p>I am using Hibernate3 with Spring 3. I am trying to start hibernate transaction using Spring.
  Given below is my configurations</p>
  
  <pre><code>&lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
          &lt;property name="configLocation" value="classpath:hibernate.cfg.xml" /&gt;
  &lt;/bean&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  </code></pre>
  
  <p>I am getting the following error while running the application.</p>
  
  <pre><code>HibernateException: get is not valid without active transaction
      at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:341)
  </code></pre>
  
  <p>I have the following line in hibernate config xml</p>
  
  <pre><code>&lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
  </code></pre>
  
  <p>The code which uses hibernate transaction is:</p>
  
  <pre><code>SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
  Session session = sessionFactory.getCurrentSession();
  Book book = (Book)session.get(Book.class, id);
  </code></pre>
  
  <p>What could be wrong in this? Is the value for current_session_context_class is anything other than thread?</p>