[appengine-java] Re: Non-Deterministic Issue with JDO Persistence
Hi Yaniv, thanks for taking a look. Actually, that isn't the issue, I've tried with various fake user accounts, and also checked the logs, the code never goes to the else statement. The log messages in the "addLocationtoUser" method also shows up, so it is definitely going into that method. In fact, when I debug in local dev environment, I can see that the location as been added to the user's collection as I step through the code. For some reason it doesn't stick - sometimes, and sometimes it does. That's what has been tricky is that it is non-deterministic. Thanks for catching the redundancy in the code, will fix that :-) On Jun 21, 2:40 am, yaniv kessler wrote: > At first glance your code seems ok, The first place I would check is: > > if(numlocs addLocationToUser(pm2, omruserkey, location); > } else { > msg = "You have exceeded the maximum number of > locations you > can save, please delete a location first."; > log.info("FAIL - Exceed max num locs"); > } > > Also as a side note, this is redundant: > > pm.newQuery(query).execute(user); > > you should simply do query.execute(...) > > Hope this helps, > > Yaniv Kessler > > maybe some locations exceed their MaxSaveLocs ??? > > On Mon, Jun 21, 2010 at 8:27 AM, shaz wrote: > > > The problem is specifically with persisting objects in a many to one > > relationship. The odd thing is that the my code was working fine, and > > then suddenly it was only persisting the objects some of the time, > > completely non-deterministic and the code hadn't changed. This has > > made it really hard to debug (it only happens sometimes and there is > > no exception, it just doesn't persist) > > > For context, the app is a route optimization solver, and there is a > > user class called OmrUser, and there are Location and Driver classes > > that map to an OmrUser (Location3 and Driver are the class names). > > (Each User saves locations and drivers, and solves optimizations to > > route them). Many locations roll up to one user, and right now > > locations save only some of the time and it is getting worse. > > > The odd thing is the Driver class persists fine, and the code is the > > same. > > > Snippet of OmrUser class (userlocs is the list collection where > > Location3 objects are saved in the many to one mapping): > > > @PersistenceCapable(identityType = IdentityType.APPLICATION, > > detachable = "true") > > public class OmrUser { > > �...@primarykey > > �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Key key; > > > �...@persistent > > private User gaeuser; > > > �...@persistent(mappedBy = "omruser") > > �...@element(dependent = "true") > > �...@order(extensions = @Extension(vendorName="datanucleus", key= > > "list-ordering", value="key asc")) > > private List userlocs; > > > �...@persistent(mappedBy = "omruser") > > �...@element(dependent = "true") > > �...@order(extensions = @Extension(vendorName="datanucleus", key= > > "list-ordering", value="key asc")) > > private List userdrivers; > > > . > > > ** > > > Snippet from Location3 class > > > @PersistenceCapable(identityType = IdentityType.APPLICATION, > > detachable = "true") > > public class Location3 implements Comparable { > > > �...@primarykey > > �...@persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Key key; > > > �...@persistent > > private User author; > > > �...@persistent > > private OmrUser omruser; > > > �...@persistent > > private String addressname; > > > . > > > * > > > Servlet that saves a location to a User > > > public class SaveLoc extends HttpServlet { > > private static final Logger log = > > Logger.getLogger(SaveLoc.class.getName()); > > > public void doGet(HttpServletRequest request, HttpServletResponse > > response) > > throws IOException { > > doPost(request, response); > >
[appengine-java] Non-Deterministic Issue with JDO Persistence
The problem is specifically with persisting objects in a many to one relationship. The odd thing is that the my code was working fine, and then suddenly it was only persisting the objects some of the time, completely non-deterministic and the code hadn't changed. This has made it really hard to debug (it only happens sometimes and there is no exception, it just doesn't persist) For context, the app is a route optimization solver, and there is a user class called OmrUser, and there are Location and Driver classes that map to an OmrUser (Location3 and Driver are the class names). (Each User saves locations and drivers, and solves optimizations to route them). Many locations roll up to one user, and right now locations save only some of the time and it is getting worse. The odd thing is the Driver class persists fine, and the code is the same. Snippet of OmrUser class (userlocs is the list collection where Location3 objects are saved in the many to one mapping): @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true") public class OmrUser { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; @Persistent private User gaeuser; @Persistent(mappedBy = "omruser") @Element(dependent = "true") @Order(extensions = @Extension(vendorName="datanucleus", key= "list-ordering", value="key asc")) private List userlocs; @Persistent(mappedBy = "omruser") @Element(dependent = "true") @Order(extensions = @Extension(vendorName="datanucleus", key= "list-ordering", value="key asc")) private List userdrivers; . ** Snippet from Location3 class @PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true") public class Location3 implements Comparable { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; @Persistent private User author; @Persistent private OmrUser omruser; @Persistent private String addressname; . * Servlet that saves a location to a User public class SaveLoc extends HttpServlet { private static final Logger log = Logger.getLogger(SaveLoc.class.getName()); public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { doPost(request, response); } public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { UserService userService = UserServiceFactory.getUserService(); User user = userService.getCurrentUser(); Integer MaxSaveLocs = Integer.parseInt(System.getProperty("opt.maxlocsave")); String address = req.getParameter("addr"); String addressname = req.getParameter("addrname"); Double addresslat = Double.parseDouble(req.getParameter("lat")); Double addresslon = Double.parseDouble(req.getParameter("lon")); Double servicetime = Double.parseDouble(req.getParameter("servicetime")); String msg = ""; List omruserquery; OmrUser thisomruser = null; Date date = new Date(); Integer numlocs; Key omruserkey; PersistenceManager pm = PMF.get().getPersistenceManager(); Location3 location = new Location3(user, address, addressname, date, addresslat, addresslon, servicetime); log.info("Attempting to Add Location - " + location.getAddressname()); try { String select_query = "select from " + OmrUser.class.getName(); Query query = pm.newQuery(select_query); query.setFilter("gaeuser == paramAuthor"); query.declareParameters("java.lang.String paramAuthor"); omruserquery = (List) pm.newQuery(query).execute(user); if(omruserquery.iterator().hasNext()) { thisomruser = omruserquery.iterator().next(); } else { thisomruser = CreateNewUser(user); pm.makePersistent(thisomruser); } } finally { numlocs = thisomruser.getNumlocs(); omruserkey = thisomruser.getKey(); pm.close(); } PersistenceManager pm2 = PMF.get().getPersistenceManager(); if(numlocshttp://groups.google.com/group/google-appengine-java?hl=en.
[appengine-java] Re: Intermittent Issue with Datastore Writes
: 2893) at org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java: 369) at org.datanucleus.TransactionImpl.commit(TransactionImpl.java: 256) at org.datanucleus.jdo.JDOTransaction.commit(JDOTransaction.java: 83) at org.datanucleus.store.appengine.jdo.DatastoreJDOTransaction.commit(DatastoreJDOTransaction.java: 56) at omr.SaveLoc.doPost(SaveLoc.java:74) at omr.SaveLoc.doGet(SaveLoc.java:24) at javax.servlet.http.HttpServlet.service(HttpServlet.java:693) at javax.servlet.http.HttpServlet.service(HttpServlet.java:806) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) at org.mortbay.jetty.servlet.ServletHandler $CachedChain.doFilter(ServletHandler.java:1166) at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java: 51) at org.mortbay.jetty.servlet.ServletHandler $CachedChain.doFilter(ServletHandler.java:1157) at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java: 43) at org.mortbay.jetty.servlet.ServletHandler $CachedChain.doFilter(ServletHandler.java:1157) at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java: 122) at org.mortbay.jetty.servlet.ServletHandler $CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java: 388) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java: 216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java: 182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java: 765) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java: 70) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java: 152) at com.google.appengine.tools.development.JettyContainerService $ApiProxyHandler.handle(JettyContainerService.java:349) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java: 152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java: 542) at org.mortbay.jetty.HttpConnection $RequestHandler.headerComplete(HttpConnection.java:923) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java: 212) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java: 404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java: 409) at org.mortbay.thread.QueuedThreadPool $PoolThread.run(QueuedThreadPool.java:582) On Jun 16, 8:05 am, shaz wrote: > Here is the code for reference. For background, there is a class > called OMRUser which is a user class, and there is Location3 class. > There is a one to many owned relationship between a user and locations > > snippet of USER class: > > @PersistenceCapable(identityType = IdentityType.APPLICATION) > public class OmrUser { > @PrimaryKey > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > private Key key; > > @Persistent > private User gaeuser; > > @Persistent(mappedBy = "omruser") > @Element(dependent = "true") > private List userlocs; > > @Persistent(mappedBy = "omruser") > @Element(dependent = "true") > private List userdrivers; > > @Persistent > private String accounttype; > > snippet of Location class: > > @PersistenceCapable(identityType = IdentityType.APPLICATION) > public class Location3 implements Comparable { > > @PrimaryKey > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > private Key key; > > @Persistent > private OmrUser omruser; > > snippet of servlet to save locations > > PersistenceManager pm = PMF.get().getPersistenceManager(); > Transaction tx = pm.currentTransaction(); > try { > tx.begin(); > > String select_query = "select from " + > OmrUser.class.getName(); > Query query = pm.newQuery(select_query); > query.setFilter("gaeuser == paramAuthor"); > query.declareParameters("java.lang.String > paramAuthor"); > > List omruserquery = (List) > pm.newQuery(query).execute(user); > > if(omruserquery.iterator().hasNext()) { > OmrUser thisomruser = > omruserquery.iterator().next(); > if(thisomruser.getNumlocs() thisomruser.addSing
[appengine-java] Re: Intermittent Issue with Datastore Writes
Here is the code for reference. For background, there is a class called OMRUser which is a user class, and there is Location3 class. There is a one to many owned relationship between a user and locations snippet of USER class: @PersistenceCapable(identityType = IdentityType.APPLICATION) public class OmrUser { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; @Persistent private User gaeuser; @Persistent(mappedBy = "omruser") @Element(dependent = "true") private List userlocs; @Persistent(mappedBy = "omruser") @Element(dependent = "true") private List userdrivers; @Persistent private String accounttype; snippet of Location class: @PersistenceCapable(identityType = IdentityType.APPLICATION) public class Location3 implements Comparable { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; @Persistent private OmrUser omruser; snippet of servlet to save locations PersistenceManager pm = PMF.get().getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); String select_query = "select from " + OmrUser.class.getName(); Query query = pm.newQuery(select_query); query.setFilter("gaeuser == paramAuthor"); query.declareParameters("java.lang.String paramAuthor"); List omruserquery = (List) pm.newQuery(query).execute(user); if(omruserquery.iterator().hasNext()) { OmrUser thisomruser = omruserquery.iterator().next(); if(thisomruser.getNumlocs() wrote: > Hi, I have a functioning app and recently have had intermittent > problems writing to the datastore. I did not make any relevant code > changes, however in the last few days my attempts to write to the > datastore sometimes work and sometimes don't. > > I am trying to save an object that is in a many to one relationship > with an existing persisted parent. So, the logic works like this: > > - Parent pulled from the > datastore > - Child created / instantiated > using constructor > > - Parent.addSingleChild(child); // > the "addSingleChild" method > just adds the object argument to the collection of children > > - child.setParent(Parent); // sets > the Parent object to the > parent field > > I am using transactions as explained in the documentation ending with > "finally {if (tx.isActive()) {tx.rollback(); } }" > > When the servlet is called, the parent is called from the datastore > and the child object is created and added to the many to one mapping > to the pre-existing parent. > > The child should automatically be persisted, since the parent is > already persistent, and the child is added to the collection of > children that map to the parent. And it worked this way in the > past. However, to be sure, i did add a pm.makePersistent(child). > Doesn't seem to help, still have the intermittent problem. > > Any suggestions would be appreciated, and if you need to see the > actual code I can post. Thanks > > appid is omrtest -- 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 google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
[appengine-java] Intermittent Issue with Datastore Writes
Hi, I have a functioning app and recently have had intermittent problems writing to the datastore. I did not make any relevant code changes, however in the last few days my attempts to write to the datastore sometimes work and sometimes don't. I am trying to save an object that is in a many to one relationship with an existing persisted parent. So, the logic works like this: - Parent pulled from the datastore - Child created / instantiated using constructor - Parent.addSingleChild(child);// the "addSingleChild" method just adds the object argument to the collection of children - child.setParent(Parent); // sets the Parent object to the parent field I am using transactions as explained in the documentation ending with "finally {if (tx.isActive()) {tx.rollback(); } }" When the servlet is called, the parent is called from the datastore and the child object is created and added to the many to one mapping to the pre-existing parent. The child should automatically be persisted, since the parent is already persistent, and the child is added to the collection of children that map to the parent. And it worked this way in the past. However, to be sure, i did add a pm.makePersistent(child). Doesn't seem to help, still have the intermittent problem. Any suggestions would be appreciated, and if you need to see the actual code I can post. Thanks appid is omrtest -- 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 google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
[appengine-java] Need to update the type of primary key on existing objects in GAE Java
Hi, I am building a web app using GAE Java. I have a class that uses a Long ID as its primary key. I now want to create a new class that would be the parent class to this original class (a one to many relationship) however the children that already exist need to have a primary key of type "key", not the Long ID I have now. What is the best way to change the primary key to be type "key" instead of long for the existing persisted entities? Should I create a new class with primary key of type "key" and instantiate and persist new objects that copy the field values from the old ones? Or can I somehow just update the existing class? Thanks -- 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 google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
[appengine-java] Re: xmlHttp request status is 0 for google maps http geocoder
Realized the issue - didn't realize there was a cross domain restriction on AJAX. Problem solved. thanks On Nov 27, 5:09 pm, shaz wrote: > Hi, > > I am trying to submit an HTTP request via AJAX from the client to the > Google Maps Geocoding service. I keep getting a status of 0. > > I know the request is valid because when I enter the URL right into > the browser address bar I get a valid result. Here is the code (assume > 'url_string' has a valid url to the geocoding service - I have tested > this already as mentioned above): > > var request = GXmlHttp.create(); request.open("GET", url_string, > true); request.onreadystatechange = function() { if > (request.readyState == 4) { alert("STATUS IS "+ request.status); > > } } > > request.send(null); > > My app is running on Google appengine and I get the error when I try > it locally but also when I deploy and try it. > > Any help would be appreciated. -- 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 google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
[appengine-java] xmlHttp request status is 0 for google maps http geocoder
Hi, I am trying to submit an HTTP request via AJAX from the client to the Google Maps Geocoding service. I keep getting a status of 0. I know the request is valid because when I enter the URL right into the browser address bar I get a valid result. Here is the code (assume 'url_string' has a valid url to the geocoding service - I have tested this already as mentioned above): var request = GXmlHttp.create(); request.open("GET", url_string, true); request.onreadystatechange = function() { if (request.readyState == 4) { alert("STATUS IS "+ request.status); } } request.send(null); My app is running on Google appengine and I get the error when I try it locally but also when I deploy and try it. Any help would be appreciated. -- 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 google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.