【问题标题】:error on spring data jpa with gae带有 gae 的 spring 数据 jpa 错误
【发布时间】: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


    【解决方案1】:

    您似乎正在为新闻分配提要并尝试保留它,但尚未保留父需求。

    【讨论】:

    • 感谢您的回答。但我无法修复它。可以给我更多信息或代码吗?
    • @takeone 在分配任何提要之前保留新闻实体。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 2020-07-31
    • 2021-05-26
    • 1970-01-01
    • 2017-02-20
    相关资源
    最近更新 更多