在更新期间,具有Editor框架的实体从db调用中选择两次。 这可能不是问题,而是编辑框架的一个特点吗?
以下是代码段:
public class UserActivity extends BasicActivity<UserActivity.Display> {
...
interface Driver extends RequestFactoryEditorDriver<UserProxy, UserPanel> {
}
private UserProxy user;
private Driver driver;
@Inject
private Provider<UserRequestContext> userContextProvider;
...
@Inject
public UserActivity(EventBus eventBus, Display display, PlaceController placeController, WmsRequestFactory requestFactory) {
super(display, eventBus, placeController);
driver = GWT.create(Driver.class);
driver.initialize(requestFactory, (UserPanel) display);
}
...
@Override
protected void onBind() {
UserRequestContext userRequestContext = userContextProvider.get();
userRequestContext.updateUser(user);
driver.edit(user, userRequestContext);
registerHandler(display.getSaveButton().addClickHandler(
new ClickHandler() {
public void onClick(ClickEvent event) {
RequestContext context = driver.flush();
// Check for errors
if (driver.hasErrors()) {
display.getStatus().setHTML(
"<b>Errors detected locally</b>");
return;
}
// Send the request
context.fire();
}
}));
...
点击保存按钮后的休眠输出:
[INFO] Hibernate: select user0_.ID as ID1_0_, user0_.CREATED as CREATED1_0_, user0_.MODIFIED as MODIFIED1_0_, user0_.version as version1_0_, user0_.BIRTH_DATE
as BIRTH5_1_0_, user0_.EMAIL as EMAIL1_0_, user0_.FIRST_NAME as FIRST7_1_0_, user0_.LAST_NAME as LAST8_1_0_, user0_.LOGIN as LOGIN1_0_, user0_.PASSWORD as PASS
WORD1_0_ from USER user0_ where user0_.ID=?
[INFO] Hibernate: select user0_.ID as ID1_0_, user0_.CREATED as CREATED1_0_, user0_.MODIFIED as MODIFIED1_0_, user0_.version as version1_0_, user0_.BIRTH_DATE
as BIRTH5_1_0_, user0_.EMAIL as EMAIL1_0_, user0_.FIRST_NAME as FIRST7_1_0_, user0_.LAST_NAME as LAST8_1_0_, user0_.LOGIN as LOGIN1_0_, user0_.PASSWORD as PASS
WORD1_0_ from USER user0_ where user0_.ID=?
[INFO] Hibernate: update USER set MODIFIED=?, version=?, BIRTH_DATE=?, EMAIL=?, FIRST_NAME=?, LAST_NAME=?, LOGIN=?, PASSWORD=? where ID=? and version=?
这是正常的吗?
答案 0 :(得分:0)
在GWT Google小组上回答:https://groups.google.com/d/msg/google-web-toolkit/T4N1puddcS4/vV1wYZ6n9EUJ
在此复制以供参考和使用:
首先,这与编辑框架无关,但与RequestFactory无关。
如果您没有使用Locator
,或者您没有覆盖isLive()
的{{1}}方法,则这是预期的行为:这就是RequestFactory确定是否在将响应发送给客户端之前,实体仍处于“活动状态”。如果不是,那么它将告诉客户端该实体已被删除(使用Locator
在EventBus上发送EntityProxyChange
事件。 WriteOperation.DELETED
的默认实现是isLive(entity)
,这也是在没有find(entity.get()) != null
实体的情况下发生的情况(区别在于您可以覆盖Locator
isLive()更改默认实现,例如,更优化的实现。)