title: What's wrong in my confguration spring sessionFactory configuration?
body: <p>First of all, I can't use Spring's <code>@Transactional</code> annotation. I have to use exactly JTA which in out EJB-container. Currecntly I'm using <code>JBoss AS 7.0 Web-Profile</code>. So what I need to do is configure Hibernate's session factory to correctly work with <code>JTA</code>-transaction inside the <code>Spring</code>'s Envirnoment. My current configuration:</p>
  
  <p>piece of the <code>context.xml</code> configuration:</p>
  
  <pre><code>&lt;tx:annotation-driven/&gt;
  &lt;tx:jta-transaction-manager  /&gt;
  
  &lt;!-- Some other beans --&gt;
  
  &lt;bean id="userTransaction" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
      &lt;property name="jndiName" value="java:comp/UserTransaction"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              &lt;value&gt;com.badmitrii.db.entity.Employee&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;
          &lt;/props&gt;            
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
      &lt;property name="userTransaction" ref="userTransaction"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>DAO-method:</p>
  
  <pre><code>public Player getPlayerById(Integer id){
      try {
          userTransaction.begin();
      } catch (Exception e) { }
  
      //Here is obtaining a Criteria object and setting Restrictions
  
      try {
          userTransaction.commit();
      } catch (Exception e) { }
      return (Player) criteria.uniqueResult();
  }
  </code></pre>
  
  <p>But, I got the following excpetion when I was trying to get Session in the DAO method:</p>
  
  <pre><code>org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread
      org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:134)
      org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1024)
      com.badmitrii.db.dao.EmployeeDAOImpl.getEmployeeById(EmployeeDAOImpl.java:34)
      com.badmitrii.EmployeeListController.getEmployeeById(EmployeeListController.java:42)
      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:483)
      org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
      org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
  </code></pre>
  
  <p>How to configure it correctly?</p>