Hi !
I am using Hibernate in a java project.
I have the next method named "getExamenPorCodInterno":
Code:
public class AdminExamen {
...
public Examen
getExamenPorCodInterno(String codigoInternoExamen)
{
Examen examen = null ;
SessionFactory sessionFactory = null ;
Session session = null ;
Transaction tx = null ;
try {
sessionFactory = HibernateUtil.getSessionFactory() ;
session = sessionFactory.openSession(); /* line 161*/
tx = session.beginTransaction();
Query getByDocId =
session.createQuery("from Examen exa where exa.codInterno = :codInterno ");
getByDocId.setString("codInterno", codigoInternoExamen );
System.out.println("AdminExamen:getExamenPorCodInterno: ANTES de getByDocId.list()");
List result = getByDocId.list();
if ( result.size() > 0 ) {
System.out.println("AdminExamen:getExamenPorCodInterno: ( result.size()>0 )");
Object obj = result.get(0);
System.out.println("AdminExamen:getExamenPorCodInterno: obj.getClass().getName() >>" + obj.getClass().getName() );
examen = (Examen) result.get(0);
}
else if ( result.size()== 0 ) {
System.out.println("AdminExamen:getExamenPorCodInterno: ( result.size()==0 )");
}
/*
session.save(empresa);
*/
System.out.println("AdminExamen:getExamenPorCodInterno: ANTES de commit()");
tx.commit();
}
catch(Exception exc) {
if ( tx!=null ) {
tx.rollback();
}
exc.printStackTrace();
}
finally {
session.close();
}
return examen ;
}
...
}
When this method executes an error appears, and the next exception is thrown:
Code:
java.lang.NullPointerException
at org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge.nextTimestamp(RegionFactoryCacheProviderBridge.java:85)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:526)
at org.hibernate.impl.SessionFactoryImpl.openSession(SessionFactoryImpl.java:535)
at framework.ordenservicio.empresas.AdminExamen.getExamenPorCodInterno(AdminExamen.java:161)
at miappweb.DefinirValorDeExamenesDeMO.doPost(DefinirValorDeExamenesDeMO.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
java.lang.NullPointerException
at framework.ordenservicio.empresas.AdminExamen.getExamenPorCodInterno(AdminExamen.java:207)
at miappweb.DefinirValorDeExamenesDeMO.doPost(DefinirValorDeExamenesDeMO.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
at java.lang.Thread.run(Thread.java:595)
My hibernate.cfg.xml file is:
Code:
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<!-- property name="connection.driver_class">org.hsqldb.jdbcDriver</property -->
<property name="connection.url">jdbc:mysql://localhost:3306/oservicio</property>
<!-- property name="connection.url">jdbc:hsqldb:hsql://localhost</property -->
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- property name="dialect">org.hibernate.dialect.HSQLDialect</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.NoCacheProvider</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<!-- property name="hbm2ddl.auto">create</property -->
<mapping resource="Categoria.hbm.xml"/>
<mapping resource="Empresa.hbm.xml"/>
<mapping resource="Examen.hbm.xml"/>
<mapping resource="OrdenServicio.hbm.xml"/>
<mapping resource="Paciente.hbm.xml"/>
<mapping resource="Paquete.hbm.xml"/>
<mapping resource="Subcategoria.hbm.xml"/>
<mapping resource="InstanciaExamen.hbm.xml"/>
<mapping resource="TarifaExamenEmpresa.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Any help is very appreciated.
Ricardo De la Rosa