package br.com.casadocodigo.loja.conf;
import java.util.Properties;
import org.springframework.context.annotation.Bean; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
public class JPAConfiguration {
@Bean public LocalContainerEntityManagerFactoryBean entityManagerFactory() { LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
JpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
factoryBean.setJpaVendorAdapter(jpaVendorAdapter );
DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setUsername("root"); dataSource.setPassword("root"); 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;
} } ERRO
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class br.com.casadocodigo.loja.conf.JPAConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean br.com.casadocodigo.loja.conf.JPAConfiguration.entityManagerFactory()] threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/HibernateException
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean br.com.casadocodigo.loja.conf.JPAConfiguration.entityManagerFactory()] threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/HibernateException
Caused by: java.lang.ClassNotFoundException: org.hibernate.HibernateException
GRAVE: Servlet [dispatcher] in web application [/casadocodigo] threw load() exception java.lang.ClassNotFoundException: org.hibernate.HibernateException