Hi spierce7

when I began working with Google AppEngine, I had the same problem.
Well, you can´t return Objects, from persistet classes to the client.
GWT can´t handle classe with @PErsistent annotations, especially the
Key
value.

You need to define something like a DataTransferObject, of your
persisted class.
http://www.resmarksystems.com/code/
will help you, doing this, or you can code it manuell. I prefer code
it manuell.
The disadvantage of this technique is, that you have mor or less 2
classes for each
persisted class, if you want to return it to the server, that means,
if something
changes, you have to changer both classes.

Instead of doing this, you cam just return the int, String, double ...
values you
need on the client.

Your DataTransfer Class fpr PersistrenceShift would look like this:

public DataTransferShifr{

   privte Date startDate;
   private Date endDate;


}

the methods are more or less the same.

I hope this will help you.

Greets Alex




On 6 Aug., 19:48, spierce7 <spier...@gmail.com> wrote:
> Hey, so I can save data to app engine in an entity of type
> "PersistentShift", a class I made to save shift information. I've got
> 2 objects I'm saving within the class. Both are Date objects. One is
> startDate, one is endDate. I wanted to be able to query the server,
> and have a return type of PersistentShift. In order to do this it was
> recommended that I put my Persistent shift class in the Shared
> package, as opposed to having one in the client package, and one in
> the server package. I've done this, and got it to where I can save
> data again, but now I'm getting an error when I try to query that
> data. Below is the relevant code. My code compiles with no errors:
> ===========================================================================
> =
> package com.spierce7.gwt.scheduler.client;
> public class Scheduler implements EntryPoint {
>         private final SchedulerServiceAsync schedulerService =
> GWT.create(SchedulerService.class);
>         public boolean timerSet = false;
>         public void onModuleLoad() {
>                 //Date startDate = new Date();
>                 //Date endDate = new Date();
>                 //endDate.setHours(endDate.getHours()+1);
>                 //addShift(startDate, endDate);
>                 loadShifts();
>         }
>         private void loadShifts() {
>                 schedulerService.getShifts(new
> AsyncCallback<List<PersistentShift>>() {
>                         public void onFailure(Throwable error) {
>                                 Window.alert(error.getMessage());
>                         }
>                         public void onSuccess(List<PersistentShift>
> results) {
>                                 Window.alert("Shift Retrieved
> Successfully!");
>                         }
>                 });
>         }
>
> }
>
> ======================================================================
> package com.spierce7.gwt.scheduler.shared;
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public final class PersistentShift implements IsSerializable {
>         @PrimaryKey
>         @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>         public Long id;
>         @Persistent
>         public Date startDate;
>         @Persistent
>         public Date endDate;
>         public PersistentShift() {}
>         public PersistentShift(Date startDate, Date endDate) {
>                 this.startDate = startDate;
>                 this.endDate = endDate;
>         }
>
> }
>
> ===============================================================
> package com.spierce7.gwt.scheduler.server;
> public class SchedulerServiceImpl extends RemoteServiceServlet
> implements SchedulerService {
>         private static final Logger LOG =
> Logger.getLogger(SchedulerServiceImpl.class.getName());
>         private static final PersistenceManagerFactory PMF =
> JDOHelper.getPersistenceManagerFactory("transactions-optional");
>         public void addShift(Date startDate, Date endDate) {
>                 PersistenceManager pm = getPersistenceManager();
>                 try {
>                         pm.makePersistent(new
> PersistentShift(startDate, endDate));
>                 } finally {
>                         pm.close();
>                 }
>         }
>         public List<PersistentShift> getShifts() {
>                 PersistenceManager pm = getPersistenceManager();
>                 List<PersistentShift> results = new
> ArrayList<PersistentShift>();
>                 try {
>                         //Query query =
> pm.newQuery(PersistentShift.class);
>                         //query.setFilter("");
>                         //query.declareParameters("SchedulerDate
> startDate SchedulerDate
> endDate");
>                         //query.setOrdering("startDate");
>                         Query query = pm.newQuery("SELECT * FROM
> PersistentShift");
>                         results = (List<PersistentShift>)
> query.execute();
>                 } finally {
>                         pm.close();
>                 }
>                 return results;
>         }
>         private PersistenceManager getPersistenceManager() {
>                 return PMF.getPersistenceManager();
>         }
>
> }
>
> ===========================================================================
> My server is calling the get shifts method, and this is the error I'm
> getting:
> org.datanucleus.store.query.AbstractJDOQLQuery <init>: Candidate
> class
> for JDOQL single-string query (PersistentShift) could not be resolved
> PersistentShift
> org.datanucleus.exceptions.ClassNotResolvedException: PersistentShift
>         at
> org.datanucleus.util.Imports.resolveClassDeclaration(Imports.java:
> 194)
>         at
> org.datanucleus.store.query.AbstractJDOQLQuery.<init>(AbstractJDOQLQuery.ja
> va:
> 114)
>         at
> org.datanucleus.store.appengine.query.JDOQLQuery.<init>(JDOQLQuery.java:
> 68)
>         at
> sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
>         at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown
> Source)
> ...
> Any help or suggestions are very welcome! Thanks!
>
> ~Scott

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appeng...@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to