I'm not serializing List's data in a single column so I don't have to force entities to update, if I'm not mistaken.
On Apr 7, 4:15 am, "Ikai L (Google)" <[email protected]> wrote: > It looks like you are changing the elements of the List themselves and not > the List. You'll have to mark the object as dirty: > > https://groups.google.com/group/google-appengine-java/browse_thread/t... > > <https://groups.google.com/group/google-appengine-java/browse_thread/t...>I'm > not completely sure this is what's going on here, as I just did a quick read > through of your code. Can you give this a try? > > > > On Fri, Mar 26, 2010 at 11:47 PM, danblack <[email protected]> wrote: > > Hello. > > I'm using JPA support for managing the App Engine datastore. > > And I've got some problems. > > > I've got an entity <Container> than contains entities <Item>(s). > > Here is my actions. > > I starts transaction then updates entity then flush updates to > > database. > > Than I gets all entities Item(s) for a container which contains my > > updated Item. > > But the list of retrieved items contains Item that does not have my > > changes. > > What is wrong with my code??? > > > I've modelled this problem. (see code) > > > @Entity > > public class Container implements Serializable { > > > private static final long serialVersionUID = 1L; > > > �...@id > > �...@generatedvalue(strategy = GenerationType.IDENTITY) > > private Key key; > > > �...@onetomany(mappedBy = "container", fetch = FetchType.LAZY) > > private List<Item> items = new ArrayList<Item>(); > > > public void setKey(Key key) { > > this.key = key; > > } > > > public Key getKey() { > > return key; > > } > > > public void setItems(List<Item> items) { > > this.items = items; > > } > > > public List<Item> getItems() { > > return items; > > } > > > } > > > @Entity > > public class Item implements Serializable { > > > private static final long serialVersionUID = 1L; > > > �...@id > > �...@generatedvalue(strategy = GenerationType.IDENTITY) > > private Key key; > > > �...@manytoone(fetch = FetchType.LAZY) > > private Container container; > > > �...@column > > private String value; > > > public void setKey(Key key) { > > this.key = key; > > } > > > public Key getKey() { > > return key; > > } > > > public void setContainer(Container container) { > > this.container = container; > > } > > > public Container getContainer() { > > return container; > > } > > > public void setValue(String value) { > > this.value = value; > > } > > > public String getValue() { > > return value; > > } > > > �...@override > > public String toString() { > > return "Item [key=" + key + ", value=" + value + "]"; > > } > > } > > > @Service("TestLocalService") > > public class LocalService { > > > protected final Log logger = LogFactory.getLog(getClass()); > > > �...@autowired > > �...@qualifier("jpaTemplate") > > protected JpaTemplate jpaTemplate; > > > �...@transactional(propagation = Propagation.REQUIRED) > > public Key createContainer() { > > Container container = new Container(); > > jpaTemplate.persist(container); > > jpaTemplate.flush(); > > logger.fatal("new container" + container.getKey()); > > return container.getKey(); > > } > > > �...@transactional(propagation = Propagation.REQUIRED) > > public Key generateItems(Key containerKey) { > > Container container = jpaTemplate.find(Container.class, > > containerKey); > > Key key = null; > > for (int i = 0; i < 5; i++) { > > Item item = new Item(); > > item.setContainer(container); > > item.setValue(Integer.toString(i)); > > jpaTemplate.persist(item); > > jpaTemplate.flush(); > > key = item.getKey(); > > logger.fatal("new item" + item); > > } > > return key; > > } > > > �...@transactional(propagation = Propagation.REQUIRED) > > public void changeItems(Key containerKey, Key itemKey) { > > Container container = jpaTemplate.find(Container.class, > > containerKey); > > Item changedItem = jpaTemplate.find(Item.class, itemKey); > > changedItem.setValue("xxx"); // > > <----------------------------------------------------------------------- > > PROBLEM HERE > > jpaTemplate.flush(); > > logger.fatal("changed item: " + changedItem); > > for (Item item : container.getItems()) { > > logger.fatal("list item: " + item); // > > <------------------------------------------------------------ PROBLEM > > HERE > > } > > } > > > public static void testListSync(LocalService service) { > > // MAIN TEST > > Key containerKey = service.createContainer(); > > Key itemKey = service.generateItems(containerKey); > > service.changeItems(containerKey, itemKey); > > } > > } > > > EXECUTION LOG > > > ### CALL createContainer > > datastore_v3.BeginTransaction > > datastore_v3.Put > > datastore_v3.Commit > > > ## LOG createContainer > > SEVERE: new containerContainer(684) > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > generateItems > > > ### CALL generateItems > > datastore_v3.BeginTransaction > > datastore_v3.Get > > datastore_v3.Put > > datastore_v3.Put > > datastore_v3.Put > > datastore_v3.Put > > datastore_v3.Put > > datastore_v3.Commit > > > ### LOG generateItems > > SEVERE: new itemItem [key=Container(684)/Item(685), value=0] > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > generateItems > > SEVERE: new itemItem [key=Container(684)/Item(686), value=1] > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > generateItems > > SEVERE: new itemItem [key=Container(684)/Item(687), value=2] > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > generateItems > > SEVERE: new itemItem [key=Container(684)/Item(688), value=3] > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > generateItems > > SEVERE: new itemItem [key=Container(684)/Item(689), value=4] > > > ### CALL changeItems > > datastore_v3.BeginTransaction > > datastore_v3.Get > > datastore_v3.Get > > datastore_v3.Put > > datastore_v3.RunQuery > > datastore_v3.Commit > > > ### LOG changeItems > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > changeItems > > SEVERE: changed item: Item [key=Container(684)/Item(689), > > value=xxx] // <----------------------------------- PROBLEM HERE > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > changeItems > > SEVERE: list item: Item [key=Container(684)/Item(685), value=0] > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > changeItems > > SEVERE: list item: Item [key=Container(684)/Item(686), value=1] > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > changeItems > > SEVERE: list item: Item [key=Container(684)/Item(687), value=2] > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > changeItems > > SEVERE: list item: Item [key=Container(684)/Item(688), value=3] > > 27.03.2010 6:16:17 ru.englishvocabulary.bl.local.test.LocalService > > changeItems > > SEVERE: list item: Item [key=Container(684)/Item(689), value=4] // > > <----------------------------------- PROBLEM HERE > > > -- > > 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. > > -- > Ikai Lan > Developer Programs Engineer, Google App > Enginehttp://googleappengine.blogspot.com|http://twitter.com/app_engine -- 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.
