GWT + Spring + Hibernate。没有任何理由

时间:2013-01-15 15:12:25

标签: spring gwt requestfactory

我正在学习如何通过以下示例将Spring与GWT和RequestFactory集成。我有一个NullPointerException,我不知道为什么。任何人都可以帮助我吗?

这是我的代码:

@Repository
public class EmployeeDAO implements IEmployeeDAO {

@PersistenceContext
private EntityManager entity;

@Override
public Employee findById(Long id) {
    Query query = entity.createQuery("from Employee where id = :param");
    query.setParameter("param", id);
    query.setMaxResults(1);
    return (Employee) query.getSingleResult();
}

@Transactional(propagation = Propagation.REQUIRED)
@Override
public void save(Employee employee) {
    entity.merge(employee);
}

@Override
public void remove(Employee employee) {
    entity.remove(employee);
}

@SuppressWarnings("unchecked")
@Override
public List<Employee> getAllEmployee() {
    Query query = entity.createQuery("from Employee");
    return query.getResultList();
}
// ...
}

@Service(value = IEmployeeDAO.class, locator = DaoLocator.class)
public interface EmployeeRequestContext extends RequestContext {

Request<EmployeeProxy> findById(Long id);

Request<Void> save(EmployeeProxy employee);

Request<Void> remove(EmployeeProxy employee);

Request<List<EmployeeProxy>> getAllEmployee();

Request<EmployeeProxy> findOneByName(String name);

}

@ProxyFor(Employee.class)
public interface EmployeeProxy extends EntityProxy {

Long getId();

String getName();

String getSurname();

void setId(Long id);

void setName(String name);

void setSurname(String surname);

Long getVersion();

void setVersion(Long version);

}

NullPointerException是方法中的GWT入口点:

protected void refresh() {      
    context = createFactory().employeeRequest();
    final EmployeeProxy ep = context.create(EmployeeProxy.class);
    ep.setName("Jan");
    ep.setSurname("Kowalski");
    ep.setVersion(new Long(0));
    context.save(ep).fire(new Receiver<Void>() {

        @Override
        public void onSuccess(Void response) {
            employeeList.add(ep);
        }

        @Override
        public void onFailure(ServerFailure error) {
            System.out.println("error podczas zapisu");
        }

    });

    context = createFactory().employeeRequest();
    context.getAllEmployee().fire(new Receiver<List<EmployeeProxy>>() {

        @Override
        public void onSuccess(List<EmployeeProxy> response) {
            System.out.println(" " + response); // NULL
        }

        @Override
        public void onFailure(ServerFailure error) {

        }

    });
    System.out.println("Bedziemy wyswietlac dane!");
    updateTable(employeeList);
}

最后一个:创建工厂的方法:

private static EmployeeRequestFactory createFactory() {
    EmployeeRequestFactory factory = GWT.create(EmployeeRequestFactory.class);
    factory.initialize(new SimpleEventBus());
    return factory;
  }

请帮帮我......

1 个答案:

答案 0 :(得分:0)

请打印NullPointerException的堆栈跟踪。只有这样我们才能分析异常的原因。