首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google-app-engine中的约束?

google-app-engine中的约束?
EN

Stack Overflow用户
提问于 2009-08-29 00:41:53
回答 2查看 911关注 0票数 2

可以在google-app-engine中使用约束吗?这似乎不起作用... http://www.datanucleus.org/products/accessplatform_1_1/jpa/orm/constr..。

属性codingSystem和代码应该是唯一的。有解决办法吗?

代码语言:javascript
复制
@Entity
@Table(uniqueConstraints = { 
    @UniqueConstraint(columnNames = { "codingSystem", "code" }) })
public class ArticleCode {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key id;

    private String codingSystem;

    private String code;

谢谢,拉尔夫

EN

回答 2

Stack Overflow用户

发布于 2009-08-29 14:11:12

简而言之,不,他们不是。底层数据存储实现不支持全局事务,因此强制执行任意唯一性约束是不切实际的。

解决方法是使唯一组件成为密钥名称的一部分。

票数 2
EN

Stack Overflow用户

发布于 2009-08-30 21:54:01

非常感谢,它工作得很好。

这是我的新代码。

@Entity公共类ArticleCode {

代码语言:javascript
复制
@Id
private Key id;

@Column(name="codingSystem")
private String codingSystem;

@Column(name="code")
private String code;

public ArticleCode(Key parent, String codingSystem, String code) {
    this.id = KeyFactory.createKey(parent, ArticleCode.class.getSimpleName(), codingSystem + code);
    this.codingSystem = codingSystem;
    this.code = code;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1350045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档