以下のように@Extensionのアノテーションを使って簡単にリレーションを作っていた。
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Parent{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long parentId;
//以下アクセッサー
}
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Child {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key childKey;
// 親キーIDを格納するプロパティ
@Persistent
@Extension(vendorName = "datanucleus", key = "gae.parent-pk", value = "true")
private Long parentId;
//以下アクセッサー
}
必ずKey型でないといけない~みたいなドキュメントがなかったので、StringかLongでもいけるかなと、この場合はLongを指定していた。そうしたら以下のようなExceptionが出た。
javax.jdo.JDOFatalUserException: Error in meta-data for hoge.Child.parnetId: Parent pk must be of type String or com.google.appengine.api.datastore.Key.なるほどですね。
StringやKeyはOKだけどLongはNGなのですね。
0 件のコメント :
コメントを投稿