代码之家  ›  专栏  ›  技术社区  ›  antony.trupe

谷歌应用引擎数据存储多字段键

  •  0
  • antony.trupe  · 技术社区  · 16 年前
    @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable ="false")
    public class Foo implements IsSerializable {
    
     @PrimaryKey
     @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
     private Long id;
    
        @Persistent
        private Long revision;
    
        @Persistent
        private String information;
    }
    

    问题是这个对象在持久化时会不断地覆盖自己,而不是用下一个修订版创建一个新的“记录”。 传统的 RDBMS 它将是一个两列主键。

    我该怎么做呢 Google App Engine Datastore ?

    2 回复  |  直到 16 年前
        1
  •  1
  •   Nick Johnson    16 年前

    如果要保留修订历史记录,则需要为每个更新创建并写入新记录。ID唯一地标识记录-数据存储无法知道您是否也将修订视为ID的一部分。

        2
  •  1
  •   Peter Mortensen Pieter Jan Bonestroo    16 年前

    我认为这是解决问题的最好方法。

    @PersistenceCapable(identityType = IdentityType.APPLICATION,detachable = "false")
    public class Foo implements IsSerializable {
    
      @PrimaryKey
      @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
      private Long _internalId;
    
      @Persistent
      private Long id;
    
      @Persistent
      private Long revision;
    
      @Persistent
      private String information;
    }
    

    其中ID和修订被视为应用程序中的主键。