繁体   English   中英

带有Gae的Spring Data JPA错误

[英]error on spring data jpa with gae

我使用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)”的孩子分配给键为“ News(no-id-yet)”的父母。 父键是不可变的。 嵌套的异常是javax.persistence.PersistenceException:尝试将键为“ Feed(6614661952700416)”的项分配给键为“ News(no-id-yet)”的父项。 父键是不可变的

如何解决这个问题?

似乎您正在为新闻分配Feed,并尝试保留它,但是父级需求仍然没有保留。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM