Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

OI galera meu codigo quando clico no botão gravar ele da o seguinte erro. HTTP Status 500 – Internal Server Error

insira seu códiType Exception Report

Message Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Could not open connection
    org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:430)go aqui
@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(""); // modifique para a senha do seu banco
            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);
     }
}
2 respostas
solução!

Oi Adilson, tudo bem?

Possivelmente os valores de conexão são diferentes do que você utiliza na sua máquina local.

O que pode estar gerando esse erro.

            dataSource.setUsername("root");
            dataSource.setPassword(""); // modifique para a senha do seu banco

e como faço para saber as configurações da minha maquina?