0
我想使用GWT RF取回數據,但我遇到了一些麻煩。 這裏是我的工廠,代理和實體。RequestFactory接收數據
實體下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=
我想不通爲什麼會這樣......
您好,感謝您的回覆,我有hibernate-annotation和rf-apt作爲註釋處理器,我只保留rf-apt,但仍然一樣。上面發佈的入口模塊中的代碼片段在第一行中執行。我已經在eclipse中清理了項目,重啓了會話......但仍然一樣。 – Panos
ValidationTool如何/何時運行?你的項目如何啓動/部署?這是在DevMode還是prod模式?在DevMode中使用服務器代碼還是部署到另一個servlet容器中? –
項目通過eclipse在devmode中啓動,而不是在另一個servlet中啓動。我沒有做任何特殊的驗證工具,而是在構建路徑上進行。 – Panos