Question

I got problem with JDO annotations in my App Engine project. I don't understand them. Thought that i can annotate something in my code, and it somehow works is black magic. I got one simple Enity for Objectify which stores Towns names in one column and i don't know how to annotate them.

@Entity
public class Town {
    @Id
    int id;
    @Index
    String name;

    private Town() {
    }

    public Town(int id, String name){
        this.name = name;
        this.id = id;
    }
} 

And got error:

PM com.google.api.server.spi.SystemService invokeServiceMethod
INFO: cause={0}
java.lang.IllegalStateException: At path 'id': Error registering com.jagienka.entities.Town

But main question: Could someone give some examples from a to z how to use JDO annotations?

Was it helpful?

Solution 2

Your error is caused by the fact that your id has the wrong type - int is not allowed. A field annotated with @Id can only be one of the following:

  • Long
  • long
  • String

If it is of type Long then Objectify will automatically generate the id for you providing you haven't already i.e. not initialised. If it is a String or long then you always have to provide the value yourself.

As @stickfigure mentioned your question has nothing to do with JDO annotations since you're using Objectify. Change your id type to Long or long and the error disappears, like so:

@Id long id;

OTHER TIPS

GAE makes some use of the DataNucleus project under the covers, which has extensive coverage of ALL JDO (and JPA) annotations/XML. Obviously some may not apply to GAE where their datastore doesn't provide that feature.

http://www.datanucleus.org/products/accessplatform_3_1/jdo/api.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top