title: Simultaneous use of Hibernate and Spring data jpa?
body: <p>Is it possible to use Spring Data JPA (backed by Hibernate as JPA provider) and directly use Hibernate at the same time?</p>
  
  <p>The problem is that when i use JpaTransactionManager, i'm not able to retrieve current session with <code>org.hibernate.HibernateException: No Session found for current thread</code>. When i switch to HibernateTransaction manager, JPA repositories are not able to commit changes.</p>
  
  <p>Here is the part of my Spring context (with that context i'm not able to use direct Hibernate calls):</p>
  
  <pre><code>&lt;jee:jndi-lookup id="dataSource" jndi-name="jdbc/IPGCONF"/&gt;
  
  &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
        p:dataSource-ref="dataSource"&gt;
      &lt;property name="configLocation" value="classpath:hibernate.cfg.xml"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceUnitName" value="entityManagerFactory"/&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
  &lt;/bean&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
  &lt;jpa:repositories base-package="com.satgate"/&gt;
  </code></pre>
  
  <p>Example of hibernate repository:</p>
  
  <pre><code>public Collection&lt;Layer&gt; listCurrent(Carrier carrier) {
      Criteria query = sessionFactory.getCurrentSession()
                      .createCriteria(Layer.class)
                      .add(Restrictions.eq("carrier", carrier));
      query.createCriteria("bitrate")
              .addOrder(Order.desc("bitrate"))
              .add(Restrictions.eq("symbolrate", carrier.getSymbolrate()));
      return query.list();
  }
  </code></pre>
  
  <p>Example of Spring data repository definition:</p>
  
  <pre><code>public interface BitrateRepository extends PagingAndSortingRepository&lt;Bitrate, Long&gt; { }
  </code></pre>
  
  <p>Software versions:</p>
  
  <pre><code>&lt;org.springframework.version&gt;4.0.0.RELEASE&lt;/org.springframework.version&gt;
  &lt;org.springframework.data.version&gt;1.4.3.RELEASE&lt;/org.springframework.data.version&gt;
  &lt;hibernate.version&gt;4.3.0.Final&lt;/hibernate.version&gt;
  </code></pre>
  
  <p>So, the question is - is it possible to use in the same transaction (specified by @Transactional annotation) both Spring JPA repositories and direct Hibernate calls and how to achieve that?</p>