使用hibernate时,我得到nullpointer Exception和DataStoreException

时间:2015-10-19 14:16:30

标签: java hibernate

我是hibernate的新手,但是我必须对使用Hibernate的java代码做一些更改,当我尝试调用已经编写的方法时,我会遇到异常。我该怎么解决这个问题。源代码和例外如下所示。

在类objListImpl中我有以下代码:

public List<String> getList(String source)
throws DatastoreException {
source srcs = RequestingSource (source);
Integer reqstSysID = srcs.getRqstrSysId();

String sqlId = "select destinationId from Destination where stat IN ( 'OBTN', 'DLVR', 'SYS' )";
return getHibernateTemplate().find(sqlId);
}



private RequestingSource findSource(String name) throws DatastoreException
{
    try
    {
        String sql ="from Source src where src.sysId = ?";
        List<RequestingSource> reqSrcList = getHibernateTemplate().find(sql, name);

        if (reqSrcList.size() > 1)
            throw new DatastoreException("Found more than one RequestingSystem for: "+ name);

        if (reqSrcList.size() == 0)
            return null;
        return reqSrcList.get(0);
    } catch (Exception e) {
        log.error("failed to find entry for: " + name, e);
        throw new DatastoreException("failed to find : " + name, e);

    }

}

在大班我有以下代码:

  objListImpl objList = new objListImpl();
List<String> IdList = null;

try {
        batchIdList = objList.getList("FILE");
    } catch (DatastoreException e) {
        System.out.println("Unable to get the document");
        e.printStackTrace();
    }

我正在跟踪控制台上的例外情况

  09:20:35,238 ERROR objListImpl:327 - failed to find : FILE
java.lang.NullPointerException
at com.service.impl.objListImpl.findSource(objListImpl.java:318)
at com.service.impl.objListImpl.getList(objListImpl.java:441)
at com.service.impl.TestMain.main(TestMain.java:28)
Unable to get the document
com..service.DatastoreException: failed to find: FILE
at com.service.impl.findSource(objListImpl.java:328)
at com.service.impl.objListImpl.getList(objListImpl.java:441)
at com.service.impl.TestMain.main(TestMain.java:28)
Caused by: java.lang.NullPointerException
at com.service.impl.objListImpl.findSource(objListImpl.java:318)
... 2 more

0 个答案:

没有答案