Getting error message

NestedThrowablesStackTrace:
java.lang.IllegalArgumentException: can't operate on multiple entity
groups in a single transaction. found both Element {
  type: "Book"
  id: 2
}
 and Element {
  type: "Book"
  id: 4
}

fails on the line
         BookService : book.getPage(); as each book is in a separate
entity group

but why does it not fail on
        Book book = bookmark.getBook();? as each bookmark is also in a
separate entity group.

@Test
        public void listTwoBooksBySingleUser() {
                User user = new User("jo...@vegas.com", "test auth domain", 
"1234");
                userService.save(user);
                Book book1 = new Book();
                book1.setTitle("test book title 1");
                bookService.save(book1);
                Book book2 = new Book();
                book2.setTitle("test book title 2");
                bookService.save(book2);

                bookService.createBookmarkForUser(book1, user);
                bookService.createBookmarkForUser(book2, user);

                List<Book> books = bookService.listByUser(user);
                assertEquals(2,books.size());
                assertEquals("test book title 1", books.get(0).getTitle());
                assertEquals("test book title 2", books.get(1).getTitle());
        }

public class BookService {

public List<Book> listByUser(User user) {
                Query query = em.createQuery("SELECT bm FROM 
"+Bookmark.class.getName
()+" bm WHERE bm.userKeys = :userKey");
                query.setParameter("userKey", user.getKey());
                List<Bookmark> bookmarks = query.getResultList();

                List<Book> books = new ArrayList<Book>();
                for (Bookmark bookmark : bookmarks) {
                        Book book = bookmark.getBook();
                        book.getPage();
                        books.add(book);
                }
                return books;
        }
}

-- 
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.

Reply via email to