Clutch
Clutch

Reputation: 7590

Jython java call throws exception asking for 2 args when only one arg is coded

I have an Java method I want to call within my Jython servlet running on tomcat5. It looks like this:

@SuppressWarnings("unchecked")
    public School loadByName(String name) {
        List<School> school;
        school = getHibernateTemplate().find("from " + getPersistentClass().getName() + " where name = ?", name);

        return uniqueResult(school);
    }

I call it in Jython using:

foobar = SchoolDAOHibernate.loadByName('University')

It throws an error that says loadByName() expects 2 args; got 1. What other argument could it be looking for?

If i try to create an instance first such as:

foo = com.dc.sports.dao.hibernate.SchoolDaoHibernate()
foo.loadByName('University')

The first call throws an exception saying:

No visible constructors for class (com.dc.sports.dao.hibernate.SchoolDaoHibernate)

I'm assuming this is because it is a private-package:

package com.dc.sports.dao.hibernate;

...

@SuppressWarnings("unchecked")
class SchoolDaoHibernate extends AbstractDaoHibernate<School> implements SchoolDao {

So how can I get at the method?

Upvotes: 2

Views: 706

Answers (2)

Blauohr
Blauohr

Reputation: 6003

loadByName is not static. You need a instance to call it.

sdh = SchoolDAOHibernate(...) # ... any args for construction ??
sdh.loadByName('Univeristy') # 2 args :-) self (sdh) and 'University'

clearer ?

Upvotes: 2

Edward Dale
Edward Dale

Reputation: 30133

Because the loadByName method isn't static, Jython might be expecting the first argument to be an instance of SchoolDAOHibernate. If it makes sense for your design, make that method static.

Upvotes: 1

Related Questions