简体   繁体   English

自己加入谷歌应用引擎(java)

[英]self join in google app engine (java)

I have modified the guestbook example shipped with google app engine (java) to include a parent-child relationship using some sort of a 'self join'.我修改了 google app engine (java) 附带的留言簿示例,以使用某种“自连接”来包含父子关系。

Now my greeting.java file looks like this现在我的 greeting.java 文件看起来像这样

    package guestbook;

import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.users.User;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Greeting {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key id;

    @Persistent
    private User author;

    @Persistent
    private String content;

    @Persistent
    private Date date;

    @Persistent
    private Greeting parent;

    @Persistent(mappedBy="parent")
    private List<Greeting> children;

    public Greeting getParent() {
        return parent;
    }

    public void setParent(Greeting parent) {
        this.parent = parent;
    }

    public List<Greeting> getChildren() {
        return children;
    }

    public void setChildren(List<Greeting> children) {
        this.children = children;
    }

    public Greeting(User author, String content, Date date) {
        this.author = author;
        this.content = content;
        this.date = date;
    }

    public Key getId() {
        return id;
    }

    public User getAuthor() {
        return author;
    }

    public String getContent() {
        return content;
    }

    public Date getDate() {
        return date;
    }

    public void setAuthor(User author) {
        this.author = author;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}

Notice the addition of the parent and child fields, and changing the primary key type to com.google.appengine.api.datastore.Key (as shown in http://code.google.com/appengine/docs/java/datastore/relationships.html#Owned_One_to_Many_Relationships )注意父字段和子字段的添加,并将主键类型更改为 com.google.appengine.api.datastore.Key(如http://code.google.com/appengine/docs/java/datastore/所示relationships.html#Owned_One_to_Many_Relationships

Now it wont save the data to the datastore.现在它不会将数据保存到数据存储区。 I fail to understand why.我不明白为什么。 I have tried deleting the local datastore and index file(as said somewhere on the web) but it wont work.我试过删除本地数据存储和索引文件(如网上某处所说),但它不起作用。 no exceptions, nothing.没有例外,没有。

Can someone look into it and please help有人可以调查一下,请帮忙

Turns out this is a known issue in Google App Engine事实证明这是 Google App Engine 中的一个已知问题

http://code.google.com/p/datanucleus-appengine/issues/detail?id=119 http://code.google.com/p/datanucleus-appengine/issues/detail?id=119

Now I will need to change my data model to work with the App Engine现在我需要更改我的数据模型以使用 App Engine

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

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