Google Cloud DatastoreのクエリにObjectifyを使用したいと考えています。既知のキーと値のペアに基づいてレコードを見つける適切な方法は何ですか?レコードがデータベースにあり、GoogleのDatastoreビューアでこれを確認しました。ここでGoogle CloudDatastoreのfindRecordとObjectify
はNotFoundExceptionをトリガ私のメソッドスタブ、次のとおりです。ここで
@ApiMethod(name="getUser")
public User getUser() throws NotFoundException {
String filterKey = "googleId";
String filterVal = "[email protected]";
User user = OfyService.ofy().load().type(User.class).filter(filterKey, filterVal).first().now();
if (user == null) {
throw new NotFoundException("User Record does not exist");
}
return user;
}
は、Userクラスです:
@Entity
public class User {
@Id
Long id;
private HealthVault healthVault;
private String googleId;
public User(String googleId){
this.googleId = googleId;
this.healthVault = new HealthVault();
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public HealthVault getHealthVault() {
return healthVault;
}
public void setHealthVault(HealthVault healthVault) {
this.healthVault = healthVault;
}
public String getGoogleId() {
return googleId;
}
public void setGoogleId(String googleId) {
this.googleId = googleId;
}
}
回答ありがとうございます。残念ながら、私のクエリにtransactionless()を追加しても解決できませんでした。 – Jochen
Userオブジェクトを表示します。 – Yevgen
ありがとうYevgen - 私は上記のポストを更新しました。 – Jochen