Exemplo n.º 1
0
 @Bean
 public JpaTransactionManager transactionManager() {
   JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
   jpaTransactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
   jpaTransactionManager.setJpaDialect(jpaDialect());
   return jpaTransactionManager;
 }
 @Bean
 @Autowired
 public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
   JpaTransactionManager txManager = new JpaTransactionManager();
   JpaDialect jpaDialect = new HibernateJpaDialect();
   txManager.setEntityManagerFactory(entityManagerFactory);
   txManager.setJpaDialect(jpaDialect);
   return txManager;
 }
 /**
  * Eagerly initialize the JPA dialect, creating a default one for the specified
  * EntityManagerFactory if none set. Auto-detect the EntityManagerFactory's DataSource, if any.
  */
 public void afterPropertiesSet() {
   if (getEntityManagerFactory() == null) {
     throw new IllegalArgumentException("Property 'entityManagerFactory' is required");
   }
   if (getEntityManagerFactory() instanceof EntityManagerFactoryInfo) {
     EntityManagerFactoryInfo emfInfo = (EntityManagerFactoryInfo) getEntityManagerFactory();
     DataSource dataSource = emfInfo.getDataSource();
     if (dataSource != null) {
       setDataSource(dataSource);
     }
     JpaDialect jpaDialect = emfInfo.getJpaDialect();
     if (jpaDialect != null) {
       setJpaDialect(jpaDialect);
     }
   }
 }