我正在尝试使用 GWT RF 取回数据,但我遇到了一些麻烦。这是我的工厂、代理和实体。
server.domain 包下的实体:
public class Job implements Serializable {
private int id;
private String announcer;
private String applied;
private String date;
private String description;
private String email;
private String title;
private int version;
static SessionFactory factory;
static ServiceRegistry serviceRegistry;
public Job() {
try {
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new ServiceRegistryBuilder().applySettings(
configuration.getProperties()).buildServiceRegistry();
factory = configuration.buildSessionFactory(serviceRegistry);
}catch (Throwable ex) {
System.err.println("Failed to create sessionFactory object." + ex);
throw new ExceptionInInitializerError(ex);
}
}
//Setters&Getters
public void persist() {
Session session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Job job = this;
session.save(job);
tx.commit();
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
e.printStackTrace();
} finally {
session.close();
}
}
public static List<Job> findAllJobs() {
Session session = factory.openSession();
Transaction tx = null;
List<Job> list = null;
try {
tx = session.beginTransaction();
Query query = session.createQuery("select * from Job");
list = query.list();
} catch (HibernateException e) {
if (tx != null)
tx.rollback();
e.printStackTrace();
} finally {
session.close();
}
return list;
}
JobRequest 类文件包含:
Request<List<JobProxy>> findAllJobs();
和入口模块:
final EventBus eventBus = new SimpleEventBus();
JobRequestFactory requestFactory = GWT.create(JobRequestFactory.class);
requestFactory.initialize(eventBus);
JobRequest request = requestFactory.jobRequest();
JobProxy newJob = request.create(JobProxy.class);
requestFactory.jobRequest().findAllJobs().to(new Receiver<List<JobProxy>>(){
public void onSuccess(List<JobProxy> jobs)
{
System.out.println("SIZE:"+jobs.size());
}
}).fire();
最后我的错误是:
com.google.web.bindery.requestfactory.server.ServiceLayerDecorator die
SEVERE: No RequestContext for operation Lk3VEjMsjGdUyVzlgtz$ggTrjMA=
我不明白为什么会这样……