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/thread/152cdafdded18611?pli=1&auth=DQAAALsAAAAysGgvSS7DADt9mTLjZVIfRcR3Ia0xnDJnZbMuAemwe776lEU-XNeYHi4XHpY5Bifg1xWbsctkBvQx5zML0axYXo2NlqltSM4p3KzBugUeNMAkhXyhYebPm0lQcCpCpuEMiZJ5JGfnPurgwrr9v8ED7wmeYMVS1mNUkJlDtsjLTiBUckaN4zVpHE9A954YDaNF86Ph7tzt99WvOJSlKPpB5IElWR-LPXslY-8v_KJTBvSm2gqRVhib-1IBIh9QxBo <https://groups.google.com/group/google-appengine-java/browse_thread/thread/152cdafdded18611?pli=1&auth=DQAAALsAAAAysGgvSS7DADt9mTLjZVIfRcR3Ia0xnDJnZbMuAemwe776lEU-XNeYHi4XHpY5Bifg1xWbsctkBvQx5zML0axYXo2NlqltSM4p3KzBugUeNMAkhXyhYebPm0lQcCpCpuEMiZJ5JGfnPurgwrr9v8ED7wmeYMVS1mNUkJlDtsjLTiBUckaN4zVpHE9A954YDaNF86Ph7tzt99WvOJSlKPpB5IElWR-LPXslY-8v_KJTBvSm2gqRVhib-1IBIh9QxBo>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 <firewor...@gmail.com> 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 > google-appengine-j...@googlegroups.com. > To unsubscribe from this group, send email to > google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/google-appengine-java?hl=en. > > -- Ikai Lan Developer Programs Engineer, Google App Engine http://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 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.