GWT RequestFactory:如何处理具有复合主键的实体
RequestFactory 可以处理复合主键吗?
文档提到实体必须实现 getId();如果实体没有单个“id”字段,而是有多个外键字段共同构成复合主键,那么应该如何实现?
Can RequestFactory handle composite primary keys?
The documentation mentions that entities must implement getId()
; how should this be implemented in the case where entities do not have a single "id" field, but rather have multiple foreign key fields that together constitute a composite primary key?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 GWT 2.1.1 中,Id 和 Version 属性可以是 RequestFactory 知道如何传输的任何类型。基本上,任何原始类型 (
int
)、装箱类型 (Integer
) 或具有关联代理类型的任何对象。您不必自己将复合 id 简化为字符串; RF 管道可以通过使用实体类型键的持久 id 或值类型键的序列化状态来自动处理复合键。使用之前发布的示例:
如果您无法将身份简化为域类型上的单个
getId()
属性,则可以使用Locator
提供外部-定义的 id 和 version 属性。例如:问题中链接的 DevGuide 就有点过时了
2.1.1 中的 RequestFactory 更改
In GWT 2.1.1, the Id and Version properties may be of any type that RequestFactory knows how to transport. Basically, any primitive type (
int
), boxed type (Integer
), or any object that has an associated Proxy type. You don't have to reduce a composite id to a String yourself; the RF plumbing can take care of composite keys automatically by using the persistent id of an entity-type key or the serialized state of a value-type key.Using the previously-posted example:
If you can't reduce the identity to a single
getId()
property on the domain type, you can use aLocator
to provide an externally-defined id and version property. For example:The DevGuide linked from the question is a bit out of date with respect to
RequestFactory changes in 2.1.1