Item という名前の JDO エンティティの PK クラスを作成しようとしています。JPAではとても簡単でしたが、今はJDOを実践しています。私は注釈構成を使用しています。これは、2 つのクラスがどのように見えるかです。
@PersistenceCapable(table="ITEM",identityType = IdentityType.APPLICATION,
objectIdClass = ItemPK.class,schema="mgr")
public class Item {
@PrimaryKey
@Persistent(column="code")
private long code; //WHY public?
@PrimaryKey
@Persistent(column="producer")
private String producer;
@PrimaryKey
@Embedded
private ItemPK id;
@Persistent(column="price")
private double price;
@Persistent(column="name")
private String name;
@Persistent(column="description")
private String description;
[... getters/setters...]
}
ItemPK クラスを、これらの 2 つの列 (コード、プロデューサー) を持つ主キー クラスとして使用する必要があります。したがって、クラスは次のようになります。
@EmbeddedOnly
@PersistenceCapable(embeddedOnly="true",identityType=IdentityType.APPLICATION)
public class ItemPK implements Serializable{
@Persistent
@PrimaryKey
public long code;
@Persistent
@PrimaryKey
public String producer;
@Override
public String toString() {
return code+"_"+producer;
}
@Override
public int hashCode() {
[...Eclipse autogenerated...]
}
@Override
public boolean equals(Object obj) {
[...Eclipse autogenerated...]
}
}
コードを実行しようとした後に得られること:
[...Caused by]
Nested Throwables StackTrace:
Class pl.edu.pw.mini.entity.jdo.Item has been specified with an object-id class pl.edu.pw.mini.entity.jdo.ItemPK which has a field jdoStateManager which isnt Serializable. All non static fields of an objectId class must be serializable.
org.datanucleus.metadata.InvalidPrimaryKeyException: Class pl.edu.pw.mini.entity.jdo.Item has been specified with an object-id class pl.edu.pw.mini.entity.jdo.ItemPK which has a field jdoStateManager which isnt Serializable. All non static fields of an objectId class must be serializable.
エンハンサーがjdoStateManagerをItemPKに追加することを理解しているので、それはシリアライズ可能ではありません。ただし、ItemPK が組み込まれているため、jdoStateManager を取得しないか、JDO が jdoStateManager と通常のフィールドの違いを認識する必要があります。2列の主キーの埋め込みクラスを取得するために何が間違っていますか
このことを機能させる方法がわかりません。誰かが私を助けてくれますか?ここで何が間違っているのか教えてください。