如何摆脱“具有 id XXX 的持久实体具有空版本”在 GWT 中?
我目前正在开发一个应用程序,使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在进行
domainVersion != null
检查的SimpleRequestProcessor.createReturnOperations()
中设置断点。没有版本的对象是服务方法新创建的,还是客户端已经操作过的对象?如果它是新创建的,您是否会进行某种请求范围内的自动提交,以便在请求完成后分配版本?如果它是已被客户端更改的实体,请查看删除setId()
和setVersion()
方法是否有帮助。一般来说,您的EntityProxy
接口不应包含setId()
和setVersion()
方法,因为这些属性只能由您设置持久化机制。Set a breakpoint in
SimpleRequestProcessor.createReturnOperations()
where thedomainVersion != 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 thesetId()
andsetVersion()
methods helps. In general, yourEntityProxy
interface should not include thesetId()
andsetVersion()
methods, since those properties should only ever be set by your persistence mechanism.如果您使用 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.