我有三個實體的用戶,公司和地址與聲明,如下所示:問題與擁有一對一的關係,父/子關係
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent(mappedBy="creator")
@Order(extensions = @Extension(vendorName="datanucleus", key="list-ordering", value="title asc"))
private Collection<Company> companies;
@Persistent
private Address address;
. . .
}
public class Company implements Serializable {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
@Extension(vendorName="datanucleus", key="gae.parent-pk", value="true")
private Key creatorKey;
@Persistent
private User creator;
@Persistent
private Address address;
. . .
}
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Address implements Serializable{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
. . .
}
創建一個用戶後,我再堅持兩家公司用戶擁有設置它們的地址和其它信息,像這樣經過:
company.setCreatorKey(currentUser.getKey());
pm.makePersistent(company);
當我取回公司,並從該對象引用的創建者,就會出現問題。顯然,JDO認爲,兩家公司的地址屬於相對於企業用戶,並記錄了以下錯誤:
address is mapped as a 1 to 1 relationship but there is more than one enity of kind Address that is a child of User([email protected])
用戶的關鍵是
User([email protected])
的關鍵公司是
User([email protected])\Company(1)
和兩個地址的關鍵是
User([email protected])\Company(1)\Address(1)
User([email protected])\Company(1)\Address(2)
我對分層數據庫相當陌生,所以我想知道爲什麼這兩個地址被持續/解釋爲用戶的子代,而不是公司的用戶和子代的後代。什麼是這樣的情況正確的層次結構?謝謝。
下載新的SDK(1.2.2)工作。我以前使用的是1.2.1,它有問題/缺陷。謝謝彼得。 – 2009-07-17 18:48:17