On Aug 17, 1:09 am, Jaap <[email protected]> wrote:
> Hi,
>
> According 
> tohttp://code.google.com/intl/de/appengine/docs/java/datastore/creating...
>
> it is possible to set the primay keys yourself to a unique string.
> When I use the code below this email however the hosted server gives
> the following error
>
> SEVERE: [1250461028948000] javax.servlet.ServletContext log: Exception
> while dispatching incoming RPC call
> com.google.gwt.user.server.rpc.UnexpectedException: Service method
> 'public abstract java.lang.String
> org.haitsma.gwttest.client.GreetingService.greetServer
> (java.lang.String)' threw an unexpected exception:
> org.datanucleus.exceptions.NucleusUserException: The primary key for
> org.haitsma.gwttest.client.Employee is an unencoded string but the key
> of the corresponding entity in the datastore does not have a name.
> You may want to either change the primary key to be an encoded string
> (add the "gae.encoded-pk" extension), change the primary key to be of
> type com.google.appengine.api.datastore.Key, or, if you're certain
> that this class will never have a parent, change the primary key to be
> of type Long.
>
> What do I do wrong? Also when I add @Persistent annotation behind
> @PrimaryKey I get the same error.
>
> Thanks,
>
> Jaap
>
> Example code
> ----------
> import java.util.Date;
> 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;
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class Employee {
>     @PrimaryKey
>     private String name;
>
>     @Persistent
>     private Date hireDate;
>
>     public Employee(String name, Date hireDate) {
>         this.name = name;
>         this.hireDate = hireDate;
>     }
>
>         public String getName() {
>                 return name;
>         }
>
>         public void setName(String name) {
>                 this.name = name;
>         }
>
>         public Date getHireDate() {
>                 return hireDate;
>         }
>
>         public void setHireDate(Date hireDate) {
>                 this.hireDate = hireDate;
>         }
>
> }

OK the below works. I needed to  @Persistent to the primary key.

-------------------
import java.util.Date;
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;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Employee {
    @PrimaryKey
    @Persistent
    private String name;

    @Persistent
    private Date hireDate;

    public Employee(String name, Date hireDate) {
        this.name = name;
        this.hireDate = hireDate;
    }

        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        public Date getHireDate() {
                return hireDate;
        }

        public void setHireDate(Date hireDate) {
                this.hireDate = hireDate;
        }
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to