Hi, Instead of flushing, did you try a PersistenceManager.close() that should lead to the same effect ? After the close, you get a new pm via the PMF and that should do it.
regards didier On Nov 10, 10:57 pm, lp <[email protected]> wrote: > thanks for the detailed response didier. > > the layout of the entities is fine, as transactions are not used in > the application itself, but as a artefact for unit testing. > i only placed the unit tests into a transaction for the purposes of > flushing the to entityManager. > > since txn dont work for multiple entities how can i structure my unit > tests to ensure that the entity manager can perform a query on > populated data? > > ie. > > @Test > public void mytest(){ > > //populate ds with data... some how ?? > > Query query = em.createNamedQuery(PositionUser.FIND_FRIENDS) > List resultList = query.getResultList(); > assertEquals( 2, resultList.size() ); > > } > > thanks > > -lp > On Nov 10, 8:44 pm, Didier Durand <[email protected]> wrote: > > > Hi, > > > Entities that you persist in the datastore are grouped in so called > > entity groups for reason of scalability and transactionality > > > That means that the ds groups your entities on various data servers > > according to their keys: this mechanism is not transparent -> it > > generates the exception that you encounter when you touch entities > > belonging to more than 1 group in a single transaction. > > > This mechanism is specific to GAE: it means that it is not transparent > > when you migrate the source code an already existing JPA app. You may > > have to rethink your data architecture and modify code accordingly. > > > You should read the dev docs and articles: > > > 1)http://code.google.com/appengine/docs/python/datastore/keysandentityg... > > > 2)http://code.google.com/appengine/docs/java/datastore/transactions.html > > > 3)http://blog.dantup.com/2010/01/app-engine-entity-groups-contention-an... > > > 4)http://hoangle.info/2010/08/01/datastore-in-google-app-engine-entity-... > > > hope it helps > > > On Nov 10, 10:37 am, lp <[email protected]> wrote: > > > > hi all, > > > > i have been attempting to convert my existing JPA code over to GAE. > > > > All is working so far except for the unit tests. > > > > i read > > > code.google.com/appengine/docs/java/tools/localunittesting.html > > > > but it doesnt describe how to get an entityManager involved in usefull > > > unit tests. > > > > so this is my test. please advise how to achieve the functionality in > > > this test. > > > > @Test > > > public void findFriendsSimple() { > > > > PositionUser user1 = new PositionUser(); > > > user1.setFirstName("john"); > > > user1.setLastName("smith"); > > > > PositionUser user2 = new PositionUser(); > > > user2.setFirstName("mary"); > > > user2.setLastName("smith"); > > > > PositionUser user3 = new PositionUser(); > > > user3.setFirstName("barney"); > > > user3.setLastName("smith"); > > > > em.persist(user2); > > > em.persist(user3); > > > //em.flush(); <--- can use flush for non transaction test > > > > user1.getFriends().add(user2.getKey()); > > > user1.getFriends().add(user3.getKey()); > > > > em.persist(user1); > > > //em.flush(); <--- can use flush for non transaction test > > > > Query query = em.createNamedQuery(PositionUser.FIND_FRIENDS); > > > query.setParameter("userKey", user1.getKey()); > > > List resultList = query.getResultList(); > > > assertEquals( 2, resultList.size() ); > > > > } > > > > the assert is triggered > > > java.lang.AssertionError: expected:<2> but was:<0> > > > > this is because the entitymanager wont detect the persisted entities > > > that arent in a transaction. > > > > ok no problem, i will add transactions. > > > > But when i do it complains that i am adding multiple groups in a single > > > transaction. > > > > So besides the simple gae sample unit test, how are others writting > > > useful unit tests in gae? > > > > any help is most appreciated > > > > -lp -- 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.
