title: creating transactionmanager and entity manager via configuration class
body: <p>i am relatively new to spring and want to implement the spring jpa with mysql. below mentioned is my configurations...</p>
  
  <pre><code>&lt;beans ...
  &lt;context:component-scan base-package="com.pg" /&gt;
  
  &lt;mvc:annotation-driven /&gt;
  
  &lt;tx:annotation-driven/&gt;
  
  &lt;aop:aspectj-autoproxy /&gt;
  
  &lt;jpa:repositories base-package="com.pg.dao" /&gt; ...
  </code></pre>
  
  <p>My configuation class to create the datasource, transactionmanager and entitymanager is listed below.</p>
  
  <pre><code>package com.pg.conf;
  
  import java.util.Properties;
  
  import javax.persistence.EntityManagerFactory;
  import javax.sql.DataSource;
  import javax.transaction.TransactionManager;
  
  import org.apache.tomcat.dbcp.dbcp.BasicDataSource;
  import org.springframework.beans.factory.FactoryBean;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  
  @Configuration
  public class JPAConfiguration {
  
      @Bean
      public DataSource dataSource(){
          BasicDataSource datasource = new BasicDataSource();
          datasource.setDriverClassName(com.mysql.jdbc.Driver.class.getName());
          datasource.setUrl("jdbc:mydql://localhost:3306/pg1");
          datasource.setUsername("root");
          datasource.setPassword("root");
          return datasource;
      }
  
      @Bean
      public **FactoryBean&lt;EntityManagerFactory&gt;** entityManagerFactory(){
          LocalContainerEntityManagerFactoryBean containerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
          containerEntityManagerFactoryBean.setDataSource(dataSource());
          HibernateJpaVendorAdapter adaptor = new HibernateJpaVendorAdapter();
          containerEntityManagerFactoryBean.setJpaVendorAdapter(adaptor);
          containerEntityManagerFactoryBean.setPackagesToScan("com.pg.entity");
          Properties props = new Properties();        
          props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
          props.setProperty("hibernate.show_sql", "true");
          containerEntityManagerFactoryBean.setJpaProperties(props);
          return containerEntityManagerFactoryBean;
      }
  
      @Bean
      public TransactionManager transactionManager(){
          JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
          jpaTransactionManager.setDataSource(dataSource());
          **jpaTransactionManager.setEntityManagerFactory(entityManagerFactory());**
          return transactionManager();
      }
  
  }
  </code></pre>
  
  <p>i have error on the line <strong>jpaTransactionManager.setEntityManagerFactory(entityManagerFactory());</strong></p>
  
  <p>i think the returntype of the entitymanager method is not correct... even though it does not show error....</p>
  
  <p>Any help is appreciated.</p>