2009-07-30 60 views
1

我在我的領域模型GAE無主JPA關係

@Entity 
public class A { 
@Id 
private String id; 
private Key firstB; 
private Key secondB; 

// getters & setters 
} 

@Entity 
public class B { 
@Id 
private Key id; 
private String name; 
// getter & setter 
} 

KeyFactory.createKey(B.class.getSimpleName(), name)有一個無主的關係是我生成B類

密鑰的方式,我救B獨立從A,並將其分配給一個實例一段時間。問題是保存A後兩個字段firstBfirstA爲空。

任何想法我做錯了什麼?

+0

作爲參考,這個問題與此相關:http://code.google.com/appengine/docs/java/datastore/relationships.html#Unowned_Relationships – 2009-07-31 13:37:58

回答

1

Key對象默認情況下不持久,所以需要明確的註釋,這就是爲什麼你看到null值。

嘗試註釋firstBsecondB@Enumerated(這確實應該@Basicthere is a bug which prevents this from working):

@Entity 
public class A { 
    @Id 
    private String id; 

    @Enumerated 
    private Key firstB; 

    @Enumerated 
    private Key secondB; 
} 

更新:最新的SDK和DataNucleus將JAR文件現在可以正確地允許使用@Basic的。

+0

這不是在官方文檔中,所以感謝提示! – dlinsin 2009-08-02 14:48:28