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 Ab开发者_如何学PythonstractDaoHibernate<School> implements SchoolDao {
So how can I get at the method?
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 ?
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.
加载中,请稍侯......
精彩评论