error on spring data jpa with gae

孤街浪徒 提交于 2019-12-25 03:44:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!