I'am using GWT 2.4 with Hibernate and RequestFactory and I have queries like this one
contextA.getEntityById(id).with("elements").fire(new Receiver<EntityBaseProxy>() {
@Override
public void onSuccess(EntityBaseProxy entity) {
System.out.println(entity.getElements().size());
}
});
I'am little confused, when elements
, which are the children of the entity, are fetched lazily, I get a NullPointer in System.out.println(entity.getElements().size());
My first solution :
entity.getElements()
getElementsFromBd()
getElementsFromBd()
in the EntityProxygetElementsFromBd()
instead of getElementsFromBd()
Presenter
contextA.getEntityById(id).with("elementsFromDb").fire(new Receiver<EntityBaseProxy>() {
@Override
public void onSuccess(EntityBaseProxy entity) {
System.out.println(entity.getElementsFromBd().size());
}
});
Entity model
...
@Transient
public List<Element> getElementsFromDb(){
doa.getElementsFromDb(this.id);
}
...
Thanks everybody
EDIT
I ended up using a servlet that extends RequestFactoryServlet where I begin and commit the transactions
public class CustomRequestFactoryServlet extends RequestFactoryServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Transaction tx = null;
try {
Session session = HibernateUtil.getCurrentSession();
tx = session.beginTransaction();
super.service(request, response);
session.getTransaction().commit();
} finally {
if (tx != null && tx.isActive()) {
tx.rollback();
}
}
}
}