title: Spring data Jpa JavaConfig
body: <p>i'm working on a spring web application using spring data jpa lately</p>
  
  <p>i have problems with the persistence configuration :</p>
  
  <pre><code>@Configuration
  @EnableTransactionManagement
  @ComponentScan(basePackages = "com.servmed")
  @PropertySource({ "/resources/hibernate.properties" })
  @EnableJpaRepositories(basePackages = "com.servmed.repositories")
  
  public class PersistenceConfig {
  
      @Autowired
      private Environment env;
  
  
      Properties jpaProperties() {
          return new Properties() {
              {
                  setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto"));
                  setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); //allows Hibernate to generate SQL optimized for a particular relational database.
                  setProperty("hibernate.show_sql",env.getProperty("hibernate.show_sql"));
              }
          };
      }
  
      @Bean
      public LocalContainerEntityManagerFactoryBean entityManagerFactory()
      {
          HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
          vendorAdapter.setGenerateDdl(true);
          vendorAdapter.setShowSql(true);
  
          LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
          factory.setDataSource(dataSource());
          factory.setJpaVendorAdapter(vendorAdapter);
          factory.setJpaProperties(jpaProperties());
          factory.setPackagesToScan("com.servmed.models");
  
          //factory.setLoadTimeWeaver(new InstrumentationLoadTimeWeaver());
          return factory;
      }
  
      @Bean
      public PlatformTransactionManager transactionManager()
      {
          EntityManagerFactory factory = entityManagerFactory().getObject();
          return new JpaTransactionManager(factory);
      }
  
      @Bean
      public HibernateExceptionTranslator hibernateExceptionTranslator(){
          return new HibernateExceptionTranslator();
      }
  
  
      @Bean
      public DataSource dataSource() {
          BasicDataSource dataSource = new BasicDataSource();
          dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
          dataSource.setUrl(env.getProperty("jdbc.url"));
          dataSource.setUsername(env.getProperty("jdbc.user"));
          dataSource.setPassword(env.getProperty("jdbc.pass"));
  
          return dataSource;
      }
  }
  </code></pre>
  
  <p>i get this error and i can't seem to find what's wrong :</p>
  
  <pre><code>Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [com/servmed/configuration/PersistenceConfig.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory]]
  </code></pre>
  
  <p>PS: i noticed that the hibernate entity manger i added to libraries is depecated , should i replace with something else ?</p>