cbmeeks
cbmeeks

Reputation: 11420

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?

Upvotes: 0

Views: 296

Answers (1)

Justin
Justin

Reputation: 2103

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

Upvotes: 1

Related Questions