0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GoogleCloudDatastore(objectify利用)でkey検索するときのエラー

Last updated at Posted at 2018-07-05

前提

Kotlin SpringBoot + GoogleCloudDatastore
いろいろ検索しても本当に情報がでてこないので、だれにも求められていない情報なのではと思いつつ。。
キー検索したときに出たエラーと対処法をメモする。

エラーメッセージ

普通に検索してエラー

<< コード >>

        return ObjectifyService.ofy()
                .load()
                .type(HogeCloudDatastoreEntity::class.java)
                .filter("id = ", id))
                .first()
                .now()
                .toDomain()

<< エラー >>

java.lang.IllegalArgumentException: @Id fields cannot be filtered on. Perhaps you wish to use filterKey() instead?

filterKeyを使ってエラー

<< コード >>

        return ObjectifyService.ofy()
                .load()
                .type(HogeCloudDatastoreEntity::class.java)
                .filterKey(id)
                .first()
                .now()
                .toDomain()

<< エラー >>

com.google.appengine.repackaged.com.google.datastore.v1.client.DatastoreException: __key__ filter value must be a Key

正解

        return ObjectifyService.ofy()
                .load()
                .type(HogeCloudDatastoreEntity::class.java)
                .filterKey(Key.create(HogeCloudDatastoreEntity::class.java, id)
                .first()
                .now()
                .toDomain()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?