简体   繁体   中英

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'.

Now my greeting.java file looks like this

    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 )

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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