问题
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
}
Error message is
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
How to fix this problem?
回答1:
Seems you are assigning a feed to a news and trying to persist it but the parent need still haven't been persisted.
来源:https://stackoverflow.com/questions/29636204/error-on-spring-data-jpa-with-gae