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
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(
    at org.eclipse.persistence.mappings.DatabaseMapping.getAttributeValueFromObject(
    at org.eclipse.persistence.internal.descriptors.ObjectBuilder.getBaseValueForField(
    at org.eclipse.persistence.descriptors.VersionLockingPolicy.lockValueFromObject(
    at org.eclipse.persistence.descriptors.VersionLockingPolicy.addLockValuesToTranslationRow(
    ... (25 lines)
    at $Proxy183.flush(Unknown Source)
    at mypackage.MyUtilClass.remove(

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);
    } 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: 1369
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,
Previous Topic:EclipseLink JPA Multi-Tenancy - Bidirectional OneToOne - ArrayIndexOutOfBoundsException
Next Topic:Issue with deployment of EJB project
Goto Forum:

Current Time: Thu Sep 24 19:17:46 GMT 2020

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

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

Back to the top