title: java.lang.IllegalStateException: No transactional EntityManager available
body: <p>Project use Hibernate (JPA), Spring and Maven. My entity and DAO in a separate JAR.</p>
  
  <p>pom.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;project ...&gt;
      ...
      &lt;artifactId&gt;database&lt;/artifactId&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;3.5.4-Final&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;    
  &lt;/project&gt;
  </code></pre>
  
  <p>DAO:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class AbstractDAO&lt;T extends BaseEntity&gt; implements GenericDAO&lt;T&gt; {
  
  
      private final Class&lt;T&gt; persistentClass;
  
      private EntityManager entityManager;
  
      public AbstractDAO(Class&lt;T&gt; entityClass) {
          super();
          this.persistentClass = entityClass;
      }
  
      @PersistenceContext
      public void setEntityManager(EntityManager entityManager) {
          this.entityManager = entityManager;
      }
  
  
      public EntityManager getEntityManager() {
          return entityManager;
      }
  
      ...
  
      public void fooBar() {
         //Exception from this line
         Session session = getEntityManager().unwrap(Session.class);
         ...
      }
  
      ....
  </code></pre>
  
  <p>}</p>
  
  <p>I have a module, which use Spring.</p>
  
  <p>pom.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;project ...&gt;
  ...
  &lt;artifactId&gt;api&lt;/artifactId&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;${spring.version}&lt;/version&gt;
      &lt;/dependency&gt;
      ....
  &lt;/dependencies&gt;
  
   ...    
  &lt;/project&gt;
  </code></pre>
  
  <p>AppContext.xml:
  </p>
  
  <pre><code>&lt;bean id="authService" scope="singleton" class="com.test.management.AuthServiceImpl" /&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" name="EntityManagerFactory"&gt;
          &lt;property name="persistenceUnitName" value="default"&gt;&lt;/property&gt;
          &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="showSql" value="true" /&gt;
                  &lt;property name="generateDdl" value="true" /&gt;
                  &lt;property name="databasePlatform" value="${db.dialect}" /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;     
      &lt;/bean&gt;
  
      &lt;!-- Values are defined in db.properties --&gt;
      &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="${db.driver}" /&gt;
          &lt;property name="url" value="${db.url}" /&gt;
          &lt;property name="username" value="${db.username}" /&gt;
          &lt;property name="password" value="${db.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" name="TransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory"&gt;&lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven /&gt;
  
      &lt;bean id="userDAO" scope="singleton" class="com.test.database.dao.impl.UserDAOImpl"&gt;
      &lt;/bean&gt;
  
  
      &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;
  
  &lt;/beans&gt; 
  </code></pre>
  
  <p>Service:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class AuthServiceImpl implements AuthService {
  
      @Autowired
      private UserDAO userDAO;
  
  
      @Override
      public void authorization() {
          userDAO.fooBar();
  
      }
  }
  </code></pre>
  
  <p>When I'm trying to get the session from EntityManager, I catch this exception:</p>
  
  <pre><code>java.lang.IllegalStateException: No transactional EntityManager available
      at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:223)
      at $Proxy121.unwrap(Unknown Source) 
  </code></pre>