-->
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: java.lang.NullPointerException in Hibernate
PostPosted: Mon Sep 21, 2009 8:23 pm 
Newbie

Joined: Fri Sep 18, 2009 3:36 am
Posts: 1
Location: Philippines
Hi!

I have a problem in getting the list of records in Hibernate. It returns a NullPointerException during runtime everytime when I test my query. Here are the following codes that I used:

codes from HcfAutDAO.java
Code:
final public static String HQL_DATA =
      "select hcf.auauno, hcf.auapfl, hcf.auapyr, hcf.auapmo, hcf.auapda, hcf.auvfyr, hcf.auvfmo, hcf.auvfda, hcf.auvtyr, hcf.auvtmo, hcf.auvtda from phpro.edi.beans.HcfAut as hcf where hcf.aux12n = :recordId";
   
   public List readAuth(Session session, long recordId) throws UnableToReadException {
      List authList = null;
      try {
         Query query = session.createQuery(HQL_DATA).setLong("recordId", recordId);
         System.out.println("The record id is: "+ recordId);
         authList = query.list();
         
         if(!authList.isEmpty()) {
            return authList;
         } else {
            System.out.println("There are no records found.");
            return null;
         }
         
      } catch(HibernateException he) {
         log.error("Hibernate Exception: ", he);
         throw new UnableToReadException();
      }
   }


I have also checked my POJO, hibernate mapping file and hibernate configuration file and their codes are fine. I used IBM DB2 as my database. Did I made wrong in my code above or did I missed something? Any solutions and comments are welcome.

Thank you.


Top
 Profile  
 
 Post subject: Re: java.lang.NullPointerException in Hibernate
PostPosted: Tue Sep 22, 2009 1:07 am 
Beginner
Beginner

Joined: Mon Sep 14, 2009 9:29 am
Posts: 30
check for NULL value which is inserted..Use this method to check for null:

public String nullReplace(Object object, String dataType) {
String value = "";
if (object != null && !object.equals("")) {
return object.toString();
} else {
if (dataType.equalsIgnoreCase("string")||dataType.equalsIgnoreCase("char")) {
return "";
} else if (dataType.equalsIgnoreCase("integer") || dataType.equalsIgnoreCase("double")||dataType.equalsIgnoreCase("long")) {
return "0";
} else {
return value;
}
}
}


And at the time of select :
USE Corresponding NVL method


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.