views:

49

answers:

2

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?

+1  A: 

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.

scompt.com
+2  A: 

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 ?

Blauohr