为什么NetBeans Java调试器永远不会访问此代码?

时间:2012-01-18 21:15:02

标签: java hibernate debugging netbeans

我正在尝试使用NetBeans在Java中调试方法。

该方法是:

    public Integer getNumberOfClamps(Locations paLocation) {
        Integer ret = -1;
        List list = new ArrayList();

        String removeme = "ABC";

        if (paLocation == null) {
            return ret;
        }

        try {
            IO io = new IO(this.getSchemaName());
            Session session = io.getSession();

            String sql = "select count(*) from assets a join assettypes at on (at.id = a.assettype_id) ";
            sql += "where a.currentlocation_id = " + paLocation.getId() + " and at.clamp = 1 and at.active = 1;";
            list = session.createQuery(sql).list();

            // for some reason, list is empty yet MySQL reports 40 records
            // and the following two lines are never reached!
            ret = list.size();
            removeme = "WHAT???";

        } catch (Exception ex) {
            ret = -1;  // explicitly set return
        } finally {
            return ret;
        }
    }

在方法的中间,您会看到list = session.createQuery(sql).list();

出于某种原因,即使手动运行SQL,我也会返回一个空列表。我得到40个结果。

但奇怪的是,一旦.list()被调用,它会跳转到finally块并且永远不会到达其余部分!因此,对于测试,“removeme”应该等于WHAT???,但调试器会将其报告为ABC

是什么给出了?

1 个答案:

答案 0 :(得分:1)

您使用的是错误的方法。 'createQuery'期待HQL语法。将您的方法更改为'createSQLQuery'