If I recall, JDO is picky when it comes to being aware of changes made to a persisted object. For example, changing fields directly (object.field = newValue;) doesn't work - you need to use a getter/ setter (object.setField(newValue);). Perhaps you are encountering the same issue here? Does the following type of thing work?
LIst<SubEntity> list = e.getMyList(); SubEntity first = list.remove(0); list.add(first); e.setMyList(list); pm.makePersistent(e); tx.commit(); Jake On Feb 28, 11:05 am, Gunnar <gunnar....@gmail.com> wrote: > Hi, > John and Karel, you are right about the placement of the commit > statement. > It worked in the test example because I only had one instance of > MyEntity. > I don't get any exception at all in the Eclipse console! > When I add a second instance of MyEntity if fails with "Transaction is > not active" as expected. > > Now I've changed the code in the try statement like this, but still > the first sub entity is lost and no exception is thrown! > (Of cause it would fail it the list is empty.) > > List<MyEntity> results = (List<MyEntity>) query.execute(); > if (results.iterator().hasNext()) { > tx.begin(); > MyEntity e = results.iterator().next(); > List<SubEntity> list = e.getMyList(); > SubEntity first = list.remove(0); > boolean ok = list.add(first); > if (!ok) { > System.err.println("could not add first"); > } > System.out.println(list); > pm.makePersistent(e); > tx.commit(); > } > > On 28 Feb, 02:51, John Patterson <jdpatter...@gmail.com> wrote: > > > This should be throwing an exception. The JavaDocs for > > Transaction.commit() say > > Commits the transaction. Whether this call succeeds or fails, all > > subsequent method invocations on this object will throw > > IllegalStateException. > > > When something does not work as you expect the first place to look is > > the logs under your application console. > > > On 28 Feb 2010, at 05:25, Karel Alvarez wrote: > > > > dont you get any exceptions stacktrace in the server console? it > > > would help... also you are calling commit() inside the for loop, > > > although the transactions is started only once... that would crash > > > in the second iteration in a normal db server, I am not sure what > > > GAE does with it, in any case I dont think it is what you intended... > > > > On Sat, Feb 27, 2010 at 2:52 PM, Gunnar <gunnar....@gmail.com> wrote: > > > Hi, > > > I have problem with reordering a List. > > > I created a test with an entity called MyEntity which have a > > > List<SubEntity>. > > > First I persist one instance of MyEntity with a list containing 3 > > > SubEntity. > > > This works fine. Then I call a reorder servlet that moves the first > > > SubEntity to the last position in the list. > > > The result is that the first SubEntity is lost and the datastore only > > > contains 2 SubEntity instances. > > > What can be wrong? > > > Here is the reorder code: > > > > package com.google.appengine.demo; > > > > import java.io.IOException; > > > import java.util.List; > > > > import javax.jdo.PersistenceManager; > > > import javax.jdo.Query; > > > import javax.jdo.Transaction; > > > import javax.servlet.http.HttpServlet; > > > import javax.servlet.http.HttpServletRequest; > > > import javax.servlet.http.HttpServletResponse; > > > > @SuppressWarnings("serial") > > > public class ReorderServlet extends HttpServlet { > > > �...@suppresswarnings("unchecked") > > > public void doGet(HttpServletRequest req, HttpServletResponse > > > resp) > > > throws IOException { > > > PersistenceManager pm = > > > PMF.get().getPersistenceManager(); > > > Query query = pm.newQuery(MyEntity.class); > > > Transaction tx = pm.currentTransaction(); > > > try { > > > tx.begin(); > > > List<MyEntity> results = (List<MyEntity>) > > > query.execute(); > > > if (results.iterator().hasNext()) { > > > for (MyEntity e : results) { > > > List<SubEntity> list = > > > e.getMyList(); > > > SubEntity first = > > > list.remove(0); > > > boolean ok = list.add(first); > > > if (!ok) { > > > > System.err.println("could not add first"); > > > } > > > System.out.println(list); > > > pm.makePersistent(e); > > > tx.commit(); > > > } > > > } > > > } catch (Exception e) { > > > e.printStackTrace(); > > > } finally { > > > if (tx.isActive()) > > > tx.rollback(); > > > query.closeAll(); > > > pm.close(); > > > } > > > resp.setContentType("text/plain"); > > > resp.getWriter().println("reordered"); > > > } > > > } > > > > -- > > > 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-java@googlegroups.com > > > . > > > To unsubscribe from this group, send email to > > > google-appengine-java+unsubscr...@googlegroups.com > > > . > > > For more options, visit this group > > > athttp://groups.google.com/group/google-appengine-java?hl=en > > > . > > > > -- > > > 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-java@googlegroups.com > > > . > > > To unsubscribe from this group, send email to > > > google-appengine-java+unsubscr...@googlegroups.com > > > . > > > For more options, visit this group > > > athttp://groups.google.com/group/google-appengine-java?hl=en > > > . -- 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.