Created
September 13, 2017 19:50
-
-
Save keysecf/e3605b05534ef75e3b64f689a80af12b to your computer and use it in GitHub Desktop.
JPAConfiguration
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
package br.com.casadocodigo.loja.conf; | |
import java.util.Properties; | |
import javax.persistence.EntityManagerFactory; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.jdbc.datasource.DriverManagerDataSource; | |
import org.springframework.orm.jpa.JpaTransactionManager; | |
import org.springframework.orm.jpa.JpaVendorAdapter; | |
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | |
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; | |
import org.springframework.transaction.annotation.EnableTransactionManagement; | |
@EnableTransactionManagement | |
public class JPAConfiguration { | |
@Bean | |
public LocalContainerEntityManagerFactoryBean entityManagerFactory() { | |
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean(); | |
JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); | |
factoryBean.setJpaVendorAdapter(vendorAdapter); | |
DriverManagerDataSource dataSource = new DriverManagerDataSource(); | |
dataSource.setUsername("root"); | |
dataSource.setPassword("c3po"); | |
dataSource.setUrl("jdbc:mysql://localhost:3306/casadocodigo"); | |
dataSource.setDriverClassName("com.mysql.jdbc.Driver"); | |
factoryBean.setDataSource(dataSource); | |
Properties props = new Properties(); | |
props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect"); | |
props.setProperty("hibernate.show_sql", "true"); | |
props.setProperty("hibernate.hbm2ddl.auto", "update"); | |
factoryBean.setJpaProperties(props); | |
factoryBean.setPackagesToScan("br.com.casadocodigo.loja.models"); | |
return factoryBean; | |
} | |
@Bean | |
public JpaTransactionManager transactionManager(EntityManagerFactory emf){ | |
return new JpaTransactionManager(emf); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment