Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Optimistic lock - Delete
Optimistic lock - Delete [message #799970] Thu, 16 February 2012 14:17 Go to next message
Mauro Flores is currently offline Mauro FloresFriend
Messages: 84
Registered: September 2009
Location: Brasil
Member
I'm implementing optimistick lock in an entity.
When two users select at same time the same object, and both try to remove it, the first one succeeds and the second instead of getting an OptimisticLockException gets the following exception:

Caused by:(4) java.lang.NullPointerException null
    at org.eclipse.persistence.internal.descriptors.PersistenceObjectAttributeAccessor.getAttributeValueFromObject(PersistenceObjectAttributeAccessor.java:30)
    at org.eclipse.persistence.mappings.DatabaseMapping.getAttributeValueFromObject(DatabaseMapping.java:497)
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.getBaseValueForField(ObjectBuilder.java:2358)
    at org.eclipse.persistence.descriptors.VersionLockingPolicy.lockValueFromObject(VersionLockingPolicy.java:514)
    at org.eclipse.persistence.descriptors.VersionLockingPolicy.addLockValuesToTranslationRow(VersionLockingPolicy.java:105)
    ... (25 lines)
    at $Proxy183.flush(Unknown Source)
    at mypackage.MyUtilClass.remove(MyUtilClass.java:107)


The implementation of method remove is like that

  public void remove(TED entity) {
    Object key = getKey(entity);
    try {
      TED entityFind = (TED) em.getReference(entity.getClass(), key);      
      if (entityFind == null) {
          throw new RecordNotFoundException(msg);
      }
      em.remove(entityFind);
      em.flush();
    } catch (EntityNotFoundException e) {
      throw new RecordNotFoundException(msg);
    }
  }


I would expect an EntityNotFoudException, OptimiscticLockException or return null from em.getReference. But not a NullPointerException throwed by em.flush method.

Is there an explanation? should I catch a nullpointerexception?

Thanks. Mauro.
Re: Optimistic lock - Delete [message #800148 is a reply to message #799970] Thu, 16 February 2012 19:02 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
You should be getting EntityNotFoundException (or optimisticLockException if it was loaded/fetched already) instead of an NPE, so this is a bug. Please file a bug with the entity that can reliably reproduce the error, the full stacktrace and any settings used.

How was the version field mapped? I ran into various other problems using getReference when the object wasn't in the cache already, but not an NPE.

The only absolute workaround I can think of is to use find instead of getReference since it will ensure the object is there for the remove call. This should work similar to what the provider will likely need to do, since it will need to trigger the entity into the cache anyway to get the version field for the delete. The only difference is you might also get exceptions on the find call.

Best Regards,
Chris
Previous Topic:EclipseLink JPA Multi-Tenancy - Bidirectional OneToOne - ArrayIndexOutOfBoundsException
Next Topic:Issue with deployment of EJB project
Goto Forum:
  


Current Time: Fri Apr 26 04:11:40 GMT 2024

Powered by FUDForum. Page generated in 0.03624 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top