Quando executo pelo terminal no mysql o comando create database casadocodigo, ele e criado normalmente o DATABASE. Apos a criação executo o USE, depois dessa transação, executo o start no servido tomcat, executo pelo terminal SHOW TABLES, imprimindo Empty set....vazio ?
package br.com.casadocodigo.loja.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import br.com.casadocodigo.loja.daos.ProdutoDAO;
import br.com.casadocodigo.loja.models.Produto;
@Controller
public class ProdutosController {
@Autowired
private ProdutoDAO produtoDAO;
@RequestMapping("/produtos/form")
public String form() {
return "produtos/form";
}
@RequestMapping("/produtos")
public String gravar(Produto produto){
System.out.println("produto");
produtoDAO.gravar(produto);
return "produtos/ok";
}
}
package br.com.casadocodigo.loja.models;
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 titulo;
private String descricao;
private int paginas;
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public int getPaginas() {
return paginas;
}
public void setPaginas(int paginas) {
this.paginas = paginas;
}
@Override
public String toString() {
return "Produto [titulo=" + titulo + ", descricao=" + descricao + ", paginas=" + paginas + "]";
}
}
package br.com.casadocodigo.loja.daos;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import br.com.casadocodigo.loja.models.Produto;
@Repository
@Transactional
public class ProdutoDAO {
@PersistenceContext
private EntityManager manager;
public void gravar (Produto produto) {
manager.persist(produto);
}
}
package br.com.casadocodigo.loja.conf;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class ServletSpringMvc extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
// TODO Auto-generated method stub
return null;
}
@Override
protected Class<?>[] getServletConfigClasses() {
// TODO Auto-generated method stub
return new Class[] {AppWebConfiguration.class, JPAConfiguration.class};
}
@Override
protected String[] getServletMappings() {
// TODO Auto-generated method stub
return new String[] {"/"};
}
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.controllers.HomeController;
import br.com.casadocodigo.loja.daos.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;
}
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 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.caelum.loja.models");
return factoryBean;
}
@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
}
}
fev 24, 2017 12:27:00 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
ADVERTÊNCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:casadocodigo' did not find a matching property.
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server version: Apache Tomcat/7.0.75
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server built: Jan 18 2017 20:54:42 UTC
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server number: 7.0.75.0
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Name: Linux
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Version: 4.4.0-59-generic
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Architecture: amd64
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Java Home: /usr/lib/jvm/jdk/jre
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Version: 1.8.0_121-b13
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Vendor: Oracle Corporation
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_BASE: /home/rodrigo/Área de Trabalho/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_HOME: /opt/apache-tomcat-7.0.75
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.base=/home/rodrigo/Área de Trabalho/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.home=/opt/apache-tomcat-7.0.75
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dwtp.deploy=/home/rodrigo/Área de Trabalho/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Djava.endorsed.dirs=/opt/apache-tomcat-7.0.75/endorsed
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dfile.encoding=UTF-8
fev 24, 2017 12:27:00 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAÇÕES: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
fev 24, 2017 12:27:00 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["http-bio-8081"]
fev 24, 2017 12:27:00 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["ajp-bio-8010"]
fev 24, 2017 12:27:00 PM org.apache.catalina.startup.Catalina load
INFORMAÇÕES: Initialization processed in 574 ms
fev 24, 2017 12:27:00 PM org.apache.catalina.core.StandardService startInternal
INFORMAÇÕES: Starting service Catalina
fev 24, 2017 12:27:00 PM org.apache.catalina.core.StandardEngine startInternal
INFORMAÇÕES: Starting Servlet Engine: Apache Tomcat/7.0.75
fev 24, 2017 12:27:01 PM org.apache.catalina.startup.TldConfig execute
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
fev 24, 2017 12:27:01 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: Spring WebApplicationInitializers detected on classpath: [br.com.casadocodigo.loja.conf.ServletSpringMvc@188b2239]
log4j:WARN No appenders could be found for logger (br.com.casadocodigo.loja.conf.ServletSpringMvc).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
fev 24, 2017 12:27:01 PM org.apache.catalina.core.ApplicationContext log
INFORMAÇÕES: Initializing Spring FrameworkServlet 'dispatcher'
fev 24, 2017 12:27:03 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["http-bio-8081"]
fev 24, 2017 12:27:03 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["ajp-bio-8010"]
fev 24, 2017 12:27:03 PM org.apache.catalina.startup.Catalina start
INFORMAÇÕES: Server startup in 3115 ms