弹簧数据jpa与gae的错误

时间:2015-04-14 19:52:14

标签: java google-app-engine jpa spring-data google-cloud-datastore

我使用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)"到了父母   用键"新闻(no-id-yet)"。父键是不可变的;嵌套   异常是javax.persistence.PersistenceException:尝试分配   孩子用钥匙"饲料(6614661952700416)"父母用钥匙   "新闻(无-ID-还)&#34 ;.父键是不可变的

如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

似乎您正在为新闻分配Feed并尝试保留该新闻,但父级需要仍未保留。