Reputation: 43
I've a web project that includes java class with JDO annotation. My database is MongoDB. I use datanucleus in my project. To persist my java object in my database, I use this code :
ListAcc list = new ListAcc();
list.name = "created";
pm.makePersistent(list);
Then, I retrieve my document with this code :
ListAcc l = pm.getObjectById(ListAcc.class,"507675823004b91181edc746");
Until that point, everything is working. Now, I'd like to update my document. For doing that, I use this code :
Transaction tx = pm.currentTransaction();
tx.begin();
try {
ListAcc l = pm.getObjectById(ListAcc.class,"507675823004b91181edc746");
l.name = "changing";
tx.commit();
} catch(Exception e) {
tx.rollback();
}
However, this operation doesn't update my document.
Could you help me to update my document?
Thanks a lot
Upvotes: 0
Views: 90
Reputation: 15577
You mean you update a PUBLIC field on that class? Firstly its bad programming practice to use public fields, and secondly if you wish to do that in a persistence context you have to annotate the class updating these public fields as @PersistenceAware (or just use setter methods on the class). All of that is in the DN docs
Upvotes: 1