我一個基類,只提供鑑定:擴展它喜歡@Id字段沒有看到,如果它是超類?
public abstract class Identifable<T> {
@Id
private T id = null;
public T getId() {
return id;
}
public void setId(T id) {
this.id = id;
}
public boolean hasId() {
return id != null;
}
}
和幾個子類:
@Entity
@Cache
public class MyEntity extends Identifable<String> {
/* some specific attributes and methods */
}
我得到一個java.lang.IllegalStateException: @Id field 'id' in com.mypkg.MyEntity must be of type Long, long, or String
。
爲什麼?不能物化看到繼承的@Id
字段? 謝謝
其實Alfredo,雖然註釋肯定看起來相同,但操作是使用[objectify](https://code.google.com/p/objectify-appengine/) –
從objectify [文檔](https:// code.google.com/p/objectify-appengine/wiki/Entities): @Id字段可以是Long,long或String類型。如果您使用Long並保存具有空ID的實體,則使用此類標準GAE分配程序爲您生成一個數值。如果使用 字符串或原始長類型,則永遠不會自動生成值。 –