オブジェクトをデータストアに永続化する場合、永続化した特定のオブジェクトのキーをいつ (そしてどのように) 取得できますか? たとえば、次の場合:
@PersistenceCapable
public class Employee {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key id;
...
}
クエリ クラス:
public class EmployeeQuery {
// Persist a single Employee
public void persistEmployee(Employee e) {
// 1. Can I get the id at this point?
PersistenceManager pm = PMF.get().getPersistenceManager();
try {
pm.makePersistent(e);
// 2. Can I get the id at this point?
}
finally {
pm.close();
// 3. Can I get the id at this point?
}
}
...
}
PersistenceManager と PMF の情報は、http ://code.google.com/appengine/docs/java/datastore/jdo/overview.html#Getting_a_PersistenceManager_Instance にあります。
前述のように、前述の領域 (1、2、または 3) のどこで、その特定のオブジェクトの自動生成 ID を取得できますか? また、その特定のオブジェクトの ID を取得するにはどうすればよいですか? これを効率的に行う方法の提案はありますか?
ありがとう。