Boa tarde senhores, tenho uma aplicação web simples na interent que só esta lendo uma view mysql.
Porem depois de uma determinado numero de horas gera o seguinte erro:
Hibernate: select agenda0_.idTurma as idTurma1_0_, agenda0_.nome_curso as nome_cur2_0_, agenda0_.nome_curto_curso as nome_cur3_0_, agenda0_.ativo as ativo4_0_, agenda0_.Qtd_Encontros as Qtd_Enco5_0_, agenda0_.Carga_Horaria as Carga_Ho6_0_, agenda0_.url as url7_0_, agenda0_.nome_turma as nome_tur8_0_, agenda0_.nome_curto_turma as nome_cur9_0_, agenda0_.dt_inicial as dt_inic10_0_, agenda0_.dt_final as dt_fina11_0_, agenda0_.estatus as estatus12_0_ from vw_agenda agenda0_
20-Dec-2017 16:48:35.635 WARN [ajp-nio-10523-exec-7] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions SQL Error: 0, SQLState: 08003
20-Dec-2017 16:48:35.635 ERROR [ajp-nio-10523-exec-7] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions No operations allowed after connection closed.
org.hibernate.exception.JDBCConnectionException: could not prepare statement
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 30,685,023 milliseconds ago. The last packet sent successfully to the server was 30,685,024 milliseconds ago. is longer than the server configured value of ‘wait_timeout’. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property ‘autoReconnect=true’ to avoid this problem.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
< ? xml version=‘1.0’ encoding=‘utf-8’ ? >
< ! DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0 / /EN"
“http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd”>
<!-- SQL dialect -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Create if table doesn't exist or update existing one on startup -->
<property name="hibernate.hbm2ddl.auto">validate</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.connection.autoReconnect">true</property>
<property name="hibernate.connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.cache.use_query_cache">false</property>
<!-- Condiguração do c3p0 -->
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">0</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<mapping resource="br/eti/jefersonluis/site/pojo/Agenda.hbm.xml"/>
</session-factory>
<!-- PROVIDER (HIBERNATE) -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
/*public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new Configuration().configure().buildSessionFactory(
new StandardServiceRegistryBuilder().build() );
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}*/
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
@SuppressWarnings("deprecation")
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
//Configuration configuration = new Configuration().configure();
//StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties());
///return configuration.buildSessionFactory(builder.build());
Configuration configuration = new Configuration();
configuration.configure();
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
//Session session = sessionFactory.openSession();
return sessionFactory;
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
public List<Agenda> getTodos() {
List<Agenda> agendas = new ArrayList<Agenda>();
Transaction trns = null;
Session session = HibernateUtil.getSessionFactory().openSession();
try {
trns = session.beginTransaction();
agendas = session.createQuery("from Agenda").list();
} catch (RuntimeException e) {
e.printStackTrace();
} finally {
session.flush();
session.close();
}
return agendas;
}