Boa tarde, o meu projeto não está criando a tabela quando eu rodo o servidor, na hora que eu faço o insert ele diz que a tabela não existe. Ja fiz todas as verificações possiveis, tb repassei os exercicios e nda. Segue abaixo minhas classes de configuração:
JPAConfigurator:
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;
import br.com.casadocodigo.loja.modelo.Produto;
@EnableTransactionManagement
public class JPAConfiguration {
@Bean
public LocalContainerEntityManagerFactoryBean EntityManagerFactory() {
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
JpaVendorAdapter jpaVendor = new HibernateJpaVendorAdapter();
factoryBean.setJpaVendorAdapter(jpaVendor);
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setUsername("root");
dataSource.setPassword("cesinhapg");
dataSource.setUrl("jdbc:mysql://localhost/casadocodigo");
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
factoryBean.setDataSource(dataSource);
Properties prop = new Properties();
prop.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
prop.setProperty("hibernate.show_sql", "true");
prop.setProperty("hibernate.hbm2dll.auto", "update");
factoryBean.setJpaProperties(prop);
factoryBean.setPackagesToScan(Produto.class.getPackage().getName());
return factoryBean;
}
@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory em) {
return new JpaTransactionManager(em);
}
}
AppWebConfigurator:
package br.com.casadocodigo.loja.conf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import br.com.casadocodigo.loja.controller.HomeController;
import br.com.casadocodigo.loja.dao.ProdutoDAO;
@EnableWebMvc
@ComponentScan(basePackageClasses= {HomeController.class, ProdutoDAO.class})
public class AppWebConfiguration {
@Bean
public InternalResourceViewResolver internalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
}
ProdutoDAO:
package br.com.casadocodigo.loja.dao;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
import org.springframework.stereotype.Repository;
import br.com.casadocodigo.loja.modelo.Produto;
@Repository
@Transactional
public class ProdutoDAO {
@PersistenceContext
private EntityManager em;
public void gravar(Produto p) {
em.persist(p);
}
}
Produto:
package br.com.casadocodigo.loja.modelo;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
public class Produto {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String descricao;
private String titulo;
private int paginas;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public int getPaginas() {
return paginas;
}
public void setPaginas(int paginas) {
this.paginas = paginas;
}
@Override
public String toString() {
return "Titulo: " + this.titulo + " descriçao: " + this.descricao + " Numero de paginas: "
+ Integer.toString(this.paginas);
}
}
ServletSpringMVC:
package br.com.casadocodigo.loja.conf;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class ServletSpringMVC extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected Class<?>[] getRootConfigClasses() {
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class[] {AppWebConfiguration.class, JPAConfiguration.class};
}
@Override
protected String[] getServletMappings() {
return new String[] {"/"};
}
}