2009-07-30 80 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