简体   繁体   中英

Why does the NetBeans Java debugger never reach this code?

I'm trying to debug a method in Java using NetBeans.

That method is:

    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;
        }
    }

Towards the middle of the method you will see list = session.createQuery(sql).list();

For some reason, this is returning an empty list even though when the SQL is run manually, I get 40 results.

But the odd part is that once the .list() is called, it jumps to the finally block and never reaches the rest! So for testing, 'removeme' should equal WHAT??? but the debugger reports it as still ABC .

What gives?

You are using the wrong method. 'createQuery' is expecting HQL syntax. Change your method to 'createSQLQuery'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM