-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: null pointer exception when calling criteria.list()
PostPosted: Mon Mar 20, 2006 6:58 pm 
Newbie

Joined: Mon Mar 20, 2006 6:42 pm
Posts: 2
Hi I am new to Hibernate and trying to debug a colleagues code. I am geting a null pointer exception, as detailed below, the first time a query is activated via the front end. If I click back on the browser and re-initiate the code, then the query works and the correct result set is displayed on the screen.

I have debugged the code and examined the Criteria object in both instances, but it looks the same. I can't understand why the code fails on the first run, but works after that. Any help would be very appreciated.

Thanks,

Jason

Hibernate version: 3.1


Code between sessionFactory.openSession() and session.close():

Code:
public List findByCriterions(Class clazz, List restrictions)
      throws DaoException {
      List objs = new ArrayList();
     
      try {
         Session session = this.openSession();
         beginTransaction();
         Criteria criteria = session.createCriteria(clazz);
         Iterator it = restrictions.iterator();
         while (it.hasNext())
            criteria.add((Criterion) it.next());
         
         if (criteria == null) {
            log.debug("null criteria");
         }
         log.debug("about to call ----- objs = criteria.list()");
         log.debug("criteria = " + criteria.toString());
         objs = criteria.list(); //NULL POINTER EXCEPTION OCCURS HERE
         log.debug("objs = criteria.list() DONE");
         if (autoCommit)
            commitTransaction();
      } catch (HibernateException ex) {
         rollbackTransaction();
         log.error("Fail to find objects by criterions", ex);
         throw new DaoException("Fail to find objects by criterions", ex);
      } finally {
         if (autoCloseSession)
            closeSession();
      }
      return objs;
   }



Full stack trace of any exception that occurs:

Code:

2006-03-21 09:24:00,726 ERROR [LogInterceptor] RuntimeException:
java.lang.NullPointerException
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:442)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:368)
   at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
   at org.hibernate.loader.Loader.doQuery(Loader.java:661)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2150)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1492)
   at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
   at doj.icms.poas.dataaccess.hibernate.HibernateDaoImpl.findByCriterions(HibernateDaoImpl.java:376)
   at doj.icms.poas.dataaccess.implementors.NoticeTypeDaoImpl.load(NoticeTypeDaoImpl.java:45)
   at doj.icms.poas.business.NoticeTypeBO.load(NoticeTypeBO.java:65)
   at doj.icms.poas.business.manager.NoticeTypeManager.findNoticeTypeById(NoticeTypeManager.java:65)
   at doj.icms.poas.business.ejb.internet.POASInternetEJB.findNoticeTypeById(POASInternetEJB.java:81)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:683)
   at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:185)
   at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:72)
   at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:84)
   at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:297)
   at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:128)
   at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:118)
   at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:191)
   at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:122)
   at org.jboss.ejb.StatelessSessionContainer.internalInvoke(StatelessSessionContainer.java:331)
   at org.jboss.ejb.Container.invoke(Container.java:700)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:546)
   at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:367)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
   at sun.rmi.transport.Transport$1.run(Transport.java:148)
   at java.security.AccessController.doPrivileged(Native Method)
   at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
   at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
   at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
   at java.lang.Thread.run(Thread.java:536)



Name and version of the database you are using: MySQL 5.0

The generated SQL (show_sql=true):

/* criteria query */ select
this_.NTYPE_ID as NTYPE1_39_0_,
this_.NTYPE_CD as NTYPE2_39_0_,
this_.NTYPE_NM as NTYPE3_39_0_,
this_.NTYPE_DESC as NTYPE4_39_0_,
this_.NTYPE_COST as NTYPE5_39_0_,
this_.NTYPE_INSTR as NTYPE6_39_0_,
this_.ONLINE_IND as ONLINE7_39_0_,
this_.EMAIL_SUB as EMAIL8_39_0_,
this_.TMPLT_TXT as TMPLT9_39_0_,
this_.DISP_SEQ as DISP10_39_0_,
this_.ACTIVE_IND as ACTIVE11_39_0_,
this_.ROW_VER as ROW12_39_0_,
this_.CREATED_BY as CREATED13_39_0_,
this_.CREATED_DT as CREATED14_39_0_,
this_.LAST_MOD_BY as LAST15_39_0_,
this_.LAST_MOD_DT as LAST16_39_0_
from
POA_NTYPE this_
where
this_.NTYPE_ID=?
4:58,346 INFO [STDOUT] Hibernate:
/* criteria query */ select
this_.NTYPE_ID as NTYPE1_39_0_,
this_.NTYPE_CD as NTYPE2_39_0_,
this_.NTYPE_NM as NTYPE3_39_0_,
this_.NTYPE_DESC as NTYPE4_39_0_,
this_.NTYPE_COST as NTYPE5_39_0_,
this_.NTYPE_INSTR as NTYPE6_39_0_,
this_.ONLINE_IND as ONLINE7_39_0_,
this_.EMAIL_SUB as EMAIL8_39_0_,
this_.TMPLT_TXT as TMPLT9_39_0_,
this_.DISP_SEQ as DISP10_39_0_,
this_.ACTIVE_IND as ACTIVE11_39_0_,
this_.ROW_VER as ROW12_39_0_,
this_.CREATED_BY as CREATED13_39_0_,
this_.CREATED_DT as CREATED14_39_0_,
this_.LAST_MOD_BY as LAST15_39_0_,
this_.LAST_MOD_DT as LAST16_39_0_
from
POA_NTYPE this_
where
this_.NTYPE_ID=?


Top
 Profile  
 
 Post subject: sorted
PostPosted: Mon Mar 20, 2006 10:52 pm 
Newbie

Joined: Mon Mar 20, 2006 6:42 pm
Posts: 2
Hi All,

In case anyone has a similar problem, I upgraded to the latest hibernate release and got a much more informative error (than the null pointer exception i was receiving before) about the session not being open. I simply fixed the session maintenance code and everything was okay.

Cheers,

Jason


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.