带有Gae的Spring Data JPA错误 [英] error on spring data jpa with gae
问题描述
我使用Google App Engine和Spring Data JPA.
I use Google App Engine and Spring Data JPA.
@Entity
public class Feed {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key id;
private String name;
private String url;
private Date created;
public Feed() {
}
public Feed(String name, String url) {
this.name = name;
this.url = url;
this.created = new Date();
}
// Getter and Setter
}
@Entity
public class News {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Key id;
@ManyToOne
private Feed feed;
private String title;
private Text content;
private String link;
private Date created;
public News(Feed feed, String title, String content, String link) {
this.feed = feed;
this.title = title;
this.content = new Text(content);
this.link = link;
this.created = new Date();
}
//Getter and Setter
}
错误消息是
尝试将具有键"Feed(6614661952700416)"的子项分配给父项 键为新闻(no-id-yet)".父键是不可变的.嵌套的 异常是javax.persistence.PersistenceException:尝试分配 密钥为"Feed(6614661952700416)"的孩子带密钥的父级 新闻(还没有)".父键是不可变的
Attempt to assign child with key "Feed(6614661952700416)" to parent with key "News(no-id-yet)". Parent keys are immutable; nested exception is javax.persistence.PersistenceException: Attempt to assign child with key "Feed(6614661952700416)" to parent with key "News(no-id-yet)". Parent keys are immutable
如何解决此问题?
推荐答案
似乎您是在为新闻分配提要,并试图保留它,但是仍然没有保留父级的需要.
Seems you are assigning a feed to a news and trying to persist it but the parent need still haven't been persisted.
这篇关于带有Gae的Spring Data JPA错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!