【发布时间】:2015-06-20 14:04:08
【问题描述】:
我使用 Google App Engine 和 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)”的子项分配给父项 带有键“新闻(还没有)”。父键是不可变的;嵌套的 异常是 javax.persistence.PersistenceException:尝试分配 带有钥匙“Feed(6614661952700416)”的孩子到带有钥匙的父母 “新闻(还没有)”。父键是不可变的
如何解决这个问题?
【问题讨论】:
标签: java google-app-engine jpa spring-data google-cloud-datastore