title: IllegalStateException: Specified field type EntityManager is incompatible with resource type EntityManagerFactory
body: <p>I had a problem when I tried to autowire entitymanager into my DAO classes. I think I've configure it properly with <code>@PersistenceContext</code>, but the error still exists.</p>
  
  <p>Thanks in advance.</p>
  
  <p>my DAO</p>
  
  <pre><code>@Repository
  public class UserDAOImpl implements UserDAO{
  
      @Autowired
      @PersistenceContext
      private EntityManager entityManager;
  
      public void setEntityManager(EntityManager entityManager) {
         this.entityManager = entityManager;
      }
  
       ...
  }
  </code></pre>
  
  <p>my persistence.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"&gt;
  
      &lt;persistence-unit name="unit"&gt;
         &lt;properties&gt;
            &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
         &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>my hibernateContext.xml</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:tx="http://www.springframework.org/schema/tx"
  xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
  http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"&gt;
  
    &lt;!-- Auto-detect DAOs --&gt;
    &lt;context:component-scan base-package="com.plainart.dao"/&gt;
  
  
  
          &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt;
          &lt;property name="url" value="${jdbc.databaseurl}" /&gt;
          &lt;property name="username" value="${jdbc.username}" /&gt;
          &lt;property name="password" value="${jdbc.password}" /&gt;
      &lt;/bean&gt;
  
  
     &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&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 name="database" value="MYSQL" /&gt;
                  &lt;property name="showSql" value="true" /&gt;
              &lt;/bean&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;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  
  &lt;/beans&gt;
  </code></pre>