77import org .springframework .beans .factory .annotation .Autowired ;
88import org .springframework .context .annotation .Bean ;
99import org .springframework .context .annotation .ComponentScan ;
10- import org .springframework .context .annotation .Configuration ;
1110import org .springframework .context .annotation .PropertySource ;
1211import org .springframework .core .env .Environment ;
1312import org .springframework .dao .annotation .PersistenceExceptionTranslationPostProcessor ;
1413import org .springframework .jdbc .datasource .DriverManagerDataSource ;
1514import org .springframework .orm .jpa .JpaTransactionManager ;
16- import org .springframework .orm .jpa .JpaVendorAdapter ;
1715import org .springframework .orm .jpa .LocalContainerEntityManagerFactoryBean ;
1816import org .springframework .orm .jpa .vendor .HibernateJpaVendorAdapter ;
1917import org .springframework .transaction .PlatformTransactionManager ;
2018import org .springframework .transaction .annotation .EnableTransactionManagement ;
2119
2220import com .google .common .base .Preconditions ;
2321
24- @ Configuration
22+ // @Configuration
2523@ EnableTransactionManagement
2624@ PropertySource ({ "classpath:persistence-mysql.properties" })
2725@ ComponentScan ({ "org.baeldung.persistence" })
@@ -36,19 +34,20 @@ public PersistenceJPAConfig() {
3634
3735 @ Bean
3836 public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean () {
39- final LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean ();
40- factoryBean .setDataSource (restDataSource ());
41- factoryBean .setPackagesToScan (new String [] { "org.baeldung.persistence.model" });
37+ final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean ();
38+ em .setDataSource (dataSource ());
39+ em .setPackagesToScan (new String [] { "org.baeldung.persistence.model" });
4240
43- final JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter ();
44- factoryBean .setJpaVendorAdapter (vendorAdapter );
45- factoryBean .setJpaProperties (additionalProperties ());
41+ final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter ();
42+ // vendorAdapter.set
43+ em .setJpaVendorAdapter (vendorAdapter );
44+ em .setJpaProperties (additionalProperties ());
4645
47- return factoryBean ;
46+ return em ;
4847 }
4948
5049 @ Bean
51- public DataSource restDataSource () {
50+ public DataSource dataSource () {
5251 final DriverManagerDataSource dataSource = new DriverManagerDataSource ();
5352 dataSource .setDriverClassName (Preconditions .checkNotNull (env .getProperty ("jdbc.driverClassName" )));
5453 dataSource .setUrl (Preconditions .checkNotNull (env .getProperty ("jdbc.url" )));
0 commit comments