title: Taking instance of EntityManager Jpa
body: <p>I am using spring and repository level for connection to the database. I am using  EntityManagerFactory and the jpa repository. My config:</p>
  
  <pre><code>    @Bean
  public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
      LocalContainerEntityManagerFactoryBean em
              = new LocalContainerEntityManagerFactoryBean();
      em.setDataSource(dataSource());
      em.setPackagesToScan("com.project.models");
      JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
      em.setJpaVendorAdapter(vendorAdapter);
      return em;
  }
  @Bean
  public PlatformTransactionManager transactionManager(
          EntityManagerFactory emf){
      JpaTransactionManager transactionManager = new JpaTransactionManager();
      transactionManager.setEntityManagerFactory(emf);
      return transactionManager;
  }
  </code></pre>
  
  <p>But now I have a case where I want to use the EntityManager's create method. How can I take an instance of it and also where, when I am using the Jpa repository and have no concrete class for it, that implements the methods?</p>
  
  <p>I am using a repository that extends JpaRepository:</p>
  
  <pre><code>public interface MyRepository extends JpaRepository&lt;Chat, Integer&gt; {
  }
  </code></pre>
  
  <p>and then using it in my service:</p>
  
  <pre><code>@Service
  public class MyServiceImpl implements MyService {
      private MyRepository myRepository;
  
      public MyServiceImpl(MyRepository myRepository) {
          this.myRepository = myRepository;
      }
  </code></pre>
  
  <p>Should I make an abstract class that implements MyRepository so I don't have to implement all JpaRepository's methods and take the instance of the EntityManager there and how can I do it?</p>