title: Configuration hibernate jpa and spring mvc (entityManager is always null)
body: <p>Good morning , I'm still new with hibernate jpa and spring this is my first projet I make and every time i try to execute it I got npe. This is my code</p>
  
  <p>applicationContext.xml</p>
  
  <p>
     http://www.springframework.org/schema/beans/spring-beans.xsd<br>
       <a href="http://www.springframework.org/schema/tx" rel="nofollow">http://www.springframework.org/schema/tx</a>
       <a href="http://www.springframework.org/schema/tx/spring-tx.xsd" rel="nofollow">http://www.springframework.org/schema/tx/spring-tx.xsd</a>"></p>
  
  <pre><code>&lt;bean id="dao" class="com.talan.springmvc.dao.AdminDaoImpl"&gt;
  &lt;/bean&gt;
  
  
  &lt;bean id="metier" class="com.talan.springmvc.metier.AdminMetier"&gt;
      &lt;property name="dao" ref="dao" /&gt;
  &lt;/bean&gt;
  &lt;bean id="datasource"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"&gt;&lt;/property&gt;
      &lt;property name="url" value="jdbc:oracle:thin:@localhost:1521/XE"&gt;&lt;/property&gt;
      &lt;property name="username" value="system"&gt;&lt;/property&gt;
      &lt;property name="password" value="Islem1992"&gt;&lt;/property&gt;
  
  &lt;/bean&gt;
  &lt;bean id="persistenceUnitManager"
      class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"&gt;
      &lt;property name="persistenceXmlLocations"&gt;
          &lt;list&gt;
              &lt;value&gt;classpath*:META-INF/persistence.xml&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="defaultDataSource" ref="datasource"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="entityManagerFactory
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceUnitManager" ref="persistenceUnitManager"&gt;&lt;/property&gt;
      &lt;property name="dataSource" ref="datasource" /&gt;
      &lt;property name="persistenceUnitName" value="myapp"&gt;&lt;/property&gt;
      &lt;property name="jpaProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;none&lt;/prop&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  &lt;!-- &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt; 
      &lt;property name="persistenceUnitName" value="myapp"&gt;&lt;/property&gt; &lt;/bean&gt; --&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>persistence.xml</p>
  
  <pre><code>&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="myapp"
          transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Test.java</p>
  
  <p>package test;</p>
  
  <pre><code>import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  import com.talan.springmvc.entities.Agence;
  import com.talan.springmvc.entities.User;
  import com.talan.springmvc.metier.IAdminMetier;
  
  public class Test {
      public static void main(String[] args){
  
          ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"});
          IAdminMetier admin = (IAdminMetier) context.getBean("metier");
          User u = new User(1,"islem", "yeddes", "salesAgent");
          admin.addUser(u);
      }
  
  }
  </code></pre>