Java 保存图形时GWT自动删除已冻结
我将GWT2.4与编辑器和请求工厂框架一起使用。我有一个模型Trip,它有一个地址“origin”和一个地址“destination”。通过UI创建行程时,将自动创建两个地址并将其分配给行程。用户填写详细信息并保存。由于某些原因,我在尝试持久化到服务器时遇到了“autobean冻结错误”。这段代码在GWT2.3中运行,我无法切换回。我希望它不是GWT2.4中的bug。下面是我正在做的一些示例代码:Java 保存图形时GWT自动删除已冻结,java,gwt,gwt2,requestfactory,Java,Gwt,Gwt2,Requestfactory,我将GWT2.4与编辑器和请求工厂框架一起使用。我有一个模型Trip,它有一个地址“origin”和一个地址“destination”。通过UI创建行程时,将自动创建两个地址并将其分配给行程。用户填写详细信息并保存。由于某些原因,我在尝试持久化到服务器时遇到了“autobean冻结错误”。这段代码在GWT2.3中运行,我无法切换回。我希望它不是GWT2.4中的bug。下面是我正在做的一些示例代码: RequestContext request = requestFactory.request()
RequestContext request = requestFactory.request();
TripProxy trip = request.create(TripProxy.class);
trip.setOrigin(request.create(AddressProxy.class));
trip.setDestination(request.create(AddressProxy.class));
driver.edit(trip, request);
this.trip = trip;
// … on save button clicked (different method)
RequestContext request = driver.flush();
request.save(trip).with(driver.getPaths()).fire(someReceiverImpl);
结果:
java.lang.IllegalStateException: The AutoBean has been frozen
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.checkFrozen(AbstractAutoBean.java:195)
at com.google.web.bindery.autobean.shared.impl.AbstractAutoBean.setProperty(AbstractAutoBean.java:270)
at sun.reflect.GeneratedMethodAccessor53.invoke(Unknown Source)
调用fire
成功完成,但在requestfactory中的某个地方抛出了上述错误。奇怪的是,实体被保存在服务器上,但是验证并没有强制执行。当我简化模型并删除地址关联时,验证和保存工作正常。我的主要问题是autobean冻结错误;验证工作是次要的
编辑:在进一步的调查中,我发现这些实体正在使服务器正常运行,并按预期持久化。返回时将抛出上述异常。AddressProxy是一个ValueProxy,看起来RF不喜欢Trip带着这些关联返回。返回null“修复”了问题,但这显然不会长期起作用 这是由于在服务器上未使用相同的EntityManager造成的。我知道这比您要求的要多得多,但以下3个技巧已经帮了我的忙:
- 改变它的属性
- 在requestContext方法调用中使用它
- 作为响应返回的每个实体都被冻结
- 在requestContext调用中使用的每个实体都将被冻结
StudentRequest req = requestFactory.studentRequest();
s1 = req.create(StudentProxy.class);
// s1 is connected with "req" and one context is just enough for it
StudentRequest reqZZZ = requestFactory.studentRequest();
reqZZZ.edit(s1); // you cannot do it - here exception will be thrown
您肯定会收到一个例外:
java.lang.IllegalArgumentException:试图编辑以前由另一个RequestContext编辑的EntityProxy
在您有一个bean的情况下,您可能会遇到这个问题,但是您没有跟踪在以前的某个方法调用中创建或编辑bean的请求上下文。在这种情况下,您必须将之前的requestContext保存在某个位置,或者将其与实体一起发送到感兴趣的点。最好的解决方案可能是创建一些特殊的层来保存当前使用的请求StudentRequest req = requestFactory.studentRequest();
s1 = req.create(StudentProxy.class);
// s1 is connected with "req" and one context is just enough for it
StudentRequest reqZZZ = requestFactory.studentRequest();
reqZZZ.edit(s1); // you cannot do it - here exception will be thrown