Created
March 12, 2017 12:06
-
-
Save MrChebik/69b1bf4b47bf5e2560bbef2eb6c2bee3 to your computer and use it in GitHub Desktop.
jpa configuration through Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@EnableJpaRepositories(value = "ru.mrchebik.repository", entityManagerFactoryRef = "entityManagerFactoryBean", transactionManagerRef = "transactionManager") | |
@EnableTransactionManagement | |
public class PersistenceJPAConfig { | |
@Bean | |
public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() { | |
Properties properties = new Properties(); | |
properties.put("hibernate.hbm2ddl.auto", "update"); | |
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); | |
properties.put("hibernate.connection.charSet", "UTF-8"); | |
properties.put("hibernate.show_sql", "true"); | |
LocalContainerEntityManagerFactoryBean lcemfb = new LocalContainerEntityManagerFactoryBean(); | |
lcemfb.setDataSource(dataSource()); | |
lcemfb.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); | |
lcemfb.setJpaProperties(properties); | |
lcemfb.setPackagesToScan("ru.mrchebik"); | |
return lcemfb; | |
} | |
@Bean | |
public PlatformTransactionManager transactionManager(){ | |
return new JpaTransactionManager(entityManagerFactoryBean().getObject()); | |
} | |
@Bean | |
public DataSource dataSource() { | |
DriverManagerDataSource dataSource = new DriverManagerDataSource("jdbc:mysql://localhost:3306/STOMPExample", "root", "root"); | |
dataSource.setDriverClassName("com.mysql.jdbc.Driver"); | |
return dataSource; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment