package me.wbprime.springdbusecase.hibernate.java.config;


import me.wbprime.springdbusecase.hibernate.java.models.Ping;
import org.hibernate.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;
import java.util.Properties;

/**
 * Class: PersistenceContext
 * Date: 2016/04/13 18:05
 *
 * @author Elvis Wang [bo.wang35@renren-inc.com]
 */
@Configuration
@EnableTransactionManagement
@ComponentScan(basePackages = {"me.wbprime.springdbusecase.hibernate.java.dao.impl" })
public class PersistenceContext {

    @Bean
    public DataSource dataSource() {
        return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .addScript("init.sql")
            .build();
    }

    @Bean
    public SessionFactory sessionFactory() throws Exception {
        final LocalSessionFactoryBean bean = new LocalSessionFactoryBean();

        bean.setPackagesToScan(
            new String [] {"me.wbprime.springdbusecase.hibernate.java.models"}
        );

        bean.setDataSource(dataSource());

        final Properties properties = new Properties();
        properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
        properties.setProperty("hibernate.show_sql", "true");
        bean.setHibernateProperties(properties);

        bean.afterPropertiesSet();
        return bean.getObject();
    }

    @Bean
    public DataSourceTransactionManager transactionManager() {
        final DataSourceTransactionManager transactionManager = new DataSourceTransactionManager();

        transactionManager.setDataSource(dataSource());

        return transactionManager;
    }
}

@@ -57,70 +57,8 @@
 ;%0A%0A%0A
-import me.wbprime.springdbusecase.hibernate.java.models.Ping;%0A
 impo
@@ -488,16 +488,87 @@
 seType;%0A
+import org.springframework.orm.hibernate5.HibernateTransactionManager;%0A
 import o
@@ -1915,25 +1915,24 @@
  public 
-DataSourc
+Hibernat
 eTransac
@@ -1963,16 +1963,33 @@
 anager()
+ throws Exception
  %7B%0A     
@@ -1997,25 +1997,24 @@
   final 
-DataSourc
+Hibernat
 eTransac
@@ -2050,25 +2050,24 @@
 r = new 
-DataSourc
+Hibernat
 eTransac
@@ -2112,37 +2112,45 @@
 ager.set
-DataSource(dataSource
+SessionFactory(sessionFactory
 ());%0A%0A  

Change to HibernateTransactionManager for Spring