I have an entity and one of my properties is an ArrayList of objects, which is serialized. I am trying to delete one of the elements of the list and persist the entity. Everything works fine locally, but not when deployed.
My code:
@Inject
public Repository<User> userRepo;
...
Leader leader = (Leader) item.getModelObject();
...
MySession.get().getUser().getLeaders().remove(leader);
JDOHelper.makeDirty(MySession.get().getUser(), "leaders");
userRepo.persist(MySession.get().getUser());
property definition in User entity:
@Persistent(defaultFetchGroup = "true", serialized = "true")
@Extension(vendorName = "datanucleus", key = "gae.unindexed", value = "true")
private ArrayList<Leader> leaders = new ArrayList<Leader>();
I am using datanucleus-core version 1.1.6, jdo2-api 2.3-eb and datanucleus-appengine 1.0.10
It works fine when I add new items to the list, but not when I remove something – why is it so? And how can I make it work?
Making something dirty makes it dirty and nothing more; persist/flush happens after … start of next transaction (as per JDO/JPA spec) or close of PM/EM; no call to makePersistent/persist will change that. This isn’t DataNucleus “deciding for itself” not to persist an object, it’s simply following the spec.
If you use recent GAE releases (v2.0) you can have non-transactional atomic persist/delete (extension to the specs). If you use SVN trunk (v2.1) you can also have nontransactional atomic updates (extending it further still). i.e with latest code you have the equivalent of JDBC “autocommit”