如何摆脱“具有 id XXX 的持久实体具有空版本”在 GWT 中?

发布于 2024-11-14 14:10:21 字数 605 浏览 2 评论 0原文

我目前正在开发一个应用程序,使用 GWT/RequestFactory 和 Hibernate/JPA 作为持久性提供程序。

所以我开始修改我的实体类,创建EntityProxies,将版本列与相应的映射放在orm.xml中(对注释爱好者来说很抱歉,我仍然用旧方法做),让hibernate正确生成数据库模式,但是当我尝试在其中执行操作,但有一个例外:

@ProxyFor(XXXXX)
public interface UserProxy extends EntityProxy {
    public Long getId();
    public void setId(Long id);
    public Integer getVersion();
    public void setVersion(Integer version);

    // removed ...
}

“ID XXX 的持久实体具有空版本”

我查看了数据库表、版本列在那里......有一个值

所以有人可以告诉我出了什么问题吗?任何帮助将不胜感激......

非常感谢,

I am currently developing an app with GWT/RequestFactory and Hibernate/JPA as a peristence provider.

So I have started to modify my Entity classes, created EntityProxies, put the Version column with the corresponding mapping in orm.xml (sorry for annotations aficionados, I'm still doing it the old way), got hibernate generate database schema correctly but when I try to do things in it i have the exception :

@ProxyFor(XXXXX)
public interface UserProxy extends EntityProxy {
    public Long getId();
    public void setId(Long id);
    public Integer getVersion();
    public void setVersion(Integer version);

    // removed ...
}

"The persisted entity with id XXX has a null version"

I have a look at the Database table, the version column is there ... with a value

so can somebody tell me what's wrong ? Any help would be appreciated ...

thanks a lot,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

草莓味的萝莉 2024-11-21 14:10:21

在进行 domainVersion != null 检查的 SimpleRequestProcessor.createReturnOperations() 中设置断点。没有版本的对象是服务方法新创建的,还是客户端已经操作过的对象?如果它是新创建的,您是否会进行某种请求范围内的自动提交,以便在请求完成后分配版本?如果它是已被客户端更改的实体,请查看删除 setId()setVersion() 方法是否有帮助。一般来说,您的 EntityProxy 接口不应包含 setId()setVersion() 方法,因为这些属性只能由您设置持久化机制。

Set a breakpoint in SimpleRequestProcessor.createReturnOperations() where the domainVersion != null check is being made. Is the object that has no version newly-created by the service methods, or is it one that has been operated on by the client? If it's newly-created, do you have some kind of request-scoped auto-commit going on where the version would be assigned after the request has finished? If it's an entity that has been mutated by the client, see if removing the setId() and setVersion() methods helps. In general, your EntityProxy interface should not include the setId() and setVersion() methods, since those properties should only ever be set by your persistence mechanism.

江湖正好 2024-11-21 14:10:21

如果您使用 Locator 类,另一个原因可能是 Locator getVersion() 方法返回 null,而不是返回实体的版本。 Eclipse 默认生成一个 null 返回值。

If you're using a Locator class, another cause can be the Locator getVersion() method returning null instead of e.g. returning the entity's version. Eclipse generates a null return value by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文