【问题标题】:Constraints in google-app-engine?谷歌应用引擎中的约束?
【发布时间】:2009-08-29 00:41:52
【问题描述】:

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

属性codingSystem 和code 应该是唯一的。有没有 解决方法?

@Entity
@Table(uniqueConstraints = { 
    @UniqueConstraint(columnNames = { "codingSystem", "code" }) })
public class ArticleCode {

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

    private String codingSystem;

    private String code;

谢谢, 拉尔夫

【问题讨论】:

    标签: google-app-engine jpa


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      非常感谢,它工作正常。

      这是我的新代码。

      @实体 公共类文章代码 {

      @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;
      }
      

      【讨论】:

        猜你喜欢
        • 2011-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多