Skip to content

Instantly share code, notes, and snippets.

@jkubrynski
Created May 8, 2015 11:14
Show Gist options
  • Save jkubrynski/8466524b55f1d4c79b24 to your computer and use it in GitHub Desktop.
Save jkubrynski/8466524b55f1d4c79b24 to your computer and use it in GitHub Desktop.
DataConfigDev
package springtutorial.scoringsystem.data.config;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.transaction.PlatformTransactionManager;
@Configuration
@EnableJpaRepositories(basePackages = "springtutorial.scoringsystem.data.repository")
public class DataConfigDev {
@Bean
public EmbeddedDatabase h2() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).build();
}
@Bean
public AbstractEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setDataSource(h2());
entityManagerFactory.setPackagesToScan("springtutorial.scoringsystem.data.model");
entityManagerFactory.getJpaPropertyMap().put("hibernate.hbm2ddl.auto", "create");
entityManagerFactory.setPersistenceProvider(new HibernatePersistenceProvider());
return entityManagerFactory;
}
@Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment