2010-04-13 36 views
7
@Entity 
    public class Blobx { 

     private String name; 
     private BlobKey blobKey; 

     @Id 
     @GeneratedValue(strategy = GenerationType.IDENTITY) 
     private Key id; 

     //getters and setters 
    } 
@Entity 
public class Userx { 
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Key id; 
    private String name; 
    @OneToMany 
    private List<Blobx> blobs; 
    //getters and setters 
} 

堅持JPA實體而persiting上述用戶X實體對象的我我遇到
無法在App Engine中

java.lang.IllegalStateException: Field "entities.Userx.blobs" contains a persistable object that isnt persistent, but the field doesnt allow cascade-persist! 

回答

13

我認爲你需要添加一個cascade屬性,這樣的JPA提供商可以堅持級聯將新的Blobx添加到blobs。目前,JPA提供者不能像錯誤消息所報告的那樣。所以改變它是這樣的(改編CascadeType以符合您的需求):

@OneToMany(cascade = CascadeType.ALL)  
private List<Blobx> blobs; 
+0

是的他們倆 – 2010-04-13 09:08:15