Hi,
I've found issue when using JPA and trying to update OneToMany relation.
Ex. having User and Items (User can have multiple Items) and trying to clear all items and then add new items, it results in empty items list when object is fetched again.
Here's Java code:
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
User user = em.find(User.
class, userId);
Item item1 =
new Item(
"Tomatoe", 20.0d);
Item item2 =
new Item(
"Carrot", 15.0d);
user.getItems().clear();
//em.flush(); // WORKAROUND: Flush "clear"
// operation to be executed in proper order
user.addItem(item1);
user.addItem(item2);
tx.commit();
em.close();
//em.find(User.class, userId);
- it will result User with empty "items"Looks it may be related to DataNucleus bug fixed in v.3.2.1 (
http://www.datanucleus.org/news/access_platform_3_2_1.html)
I've described this issue:
http://startup-with-gae.blogspot.com/2015/05/google-app-engine-onetomany-update.htmlregards,
Maciej Arkit