OneToMany update operation fails due to bug in JPA datanucleus

82 views
Skip to first unread message

Maciej Arkit

unread,
May 10, 2015, 8:20:02 PM5/10/15
to google-a...@googlegroups.com
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.html

regards,
Maciej Arkit

Ryan (Cloud Platform Support)

unread,
May 19, 2015, 11:53:03 AM5/19/15
to google-a...@googlegroups.com, maciej...@gmail.com
Salutations Maciej,

I would recommend creating a bug report on the Public Issue Tracker. Including a full working project will expedite the processing time.

Thank you!

Maciej Arkit

unread,
May 22, 2015, 3:11:50 AM5/22/15
to google-a...@googlegroups.com
Sure, I will.
Thanks,
Maciej.

W dniu 2015-05-19 o 17:53, Ryan (Cloud Platform Support) pisze:
--
You received this message because you are subscribed to a topic in the Google Groups "Google App Engine" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-appengine/cHEU7fKbJh0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/867bed71-fee4-43df-901b-fc1ddb7c2562%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan (Cloud Platform Support)

unread,
May 22, 2015, 11:24:08 AM5/22/15
to google-a...@googlegroups.com, maciej...@gmail.com
Thank you!
To unsubscribe from this group and all its topics, send an email to google-appengine+unsubscribe@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages