gcloud数据存储使用UUID的密钥

时间:2020-10-14 02:29:45

标签: java spring-boot google-cloud-datastore uuid datastore

我是 gcloud DataStore密钥的新手。我想知道如何定义要使用UUID的密钥?

例如在下面的Instrument.java类中,如何确保Key对象使用UUID?

import java.util.Objects;
import com.google.cloud.datastore.Key;
import org.springframework.cloud.gcp.data.datastore.core.mapping.Entity;
import org.springframework.data.annotation.Id;

@Entity
public class Instrument {
    @Id
    Key instrumentId;

    private String type;

    public Instrument(String type) {
        this.type = type;
    }

    public String getType() {
        return this.type;
    }

    public void setType(String type) {
        this.type = type;
    }
}

1 个答案:

答案 0 :(得分:0)

您正在正确地指定它。

根据documentationA data class must have one and only one field dedicated to storing the primary key of the corresponding datastore entity.中的定义,因此,密钥是数据存储区实体的UUID。

在这种情况下,由于您使用的是Spring框架org.springframework.cloud.gcp,因此要定义哪个属性为键,您必须以Datastore Spring framework documentation中指定的方式使用{{ 1}}。

@Id