Bom dia Pessoal,
Estou fazendo o curso 1 de MVC Spring. nesse curso utiliza o MySQL como banco de dados. Hoje utilizo SQL Server para todas minhas aplicações. Gostaria de saber como configurar o JPA, abaixo as modificações que eu fiz e não funcionou
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("usuario");
dataSource.setPassword("senha");
dataSource.setUrl("jdbc:mysql://meu servidor/meu banco");
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
*/
dataSource.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
dataSource.setUrl("jdbc:sqlserver://meu servidor:1433;databaseName=meu banco");
dataSource.setUsername("usuario");
dataSource.setPassword("senha");
factoryBean.setDataSource(dataSource);
Properties props = new Properties();
//props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
props.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
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);
}
}