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 <[email protected]> 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
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine-java%[email protected]>
> .
> For more options, visit this group at
> http://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 [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