Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Cached Map Update NPE on element remove
Cached Map Update NPE on element remove [message #1011408] Tue, 19 February 2013 09:26 Go to next message
Cristian Oancea is currently offline Cristian Oancea
Messages: 2
Registered: February 2013
Junior Member
in 2.4.0

for a 1-M relation using a map with table key , on remove the SQL transaction is commited , but cache is not , a NPE is thrown

@OneToMany(fetch = FetchType.LAZY, targetEntity = Child.class,
mappedBy = "direct", cascade = { CascadeType.REMOVE },
orphanRemoval = true)
@MapKeyColumn(name = "child_name", table = "child", insertable = false,
updatable = false)

@Cache(type = CacheType.HARD_WEAK, size = 10000, expiry = -1,
alwaysRefresh = true, isolation = CacheIsolationType.SHARED,
coordinationType = CacheCoordinationType.INVALIDATE_CHANGED_OBJECTS)
@Cacheable(value = true)

org.eclipse.persistence.internal.queries.MapContainerPolicy

key = null
element !=null

public boolean removeFrom(Object key, Object element, Object container, AbstractSession session) {
try {
Object returnValue = null;
if (key != null) {
returnValue = ((Map)container).remove(key);
} else if (element != null) {
!!!!
returnValue = ((Map)container).remove(keyFrom(element, session));
### hier comes a NullPointerException
!!!

}
if (returnValue == null) {
return false;
} else {
return true;
}
} catch (UnsupportedOperationException ex) {
throw QueryException.methodNotValid(container, "remove(Object element)");
}
}

the keyFrom function returns a null

org.eclipse.persistence.internal.queries.MappedKeyMapContainerPolicy

public Object keyFrom(Object element, AbstractSession session) {
// key is mapped to the database table and not the object and therefore cannot be extracted from the object
if (keyMapping != null){
return null;
}
return super.keyFrom(element, session);
}

is there any solution ?

If I use Set it works.

[Updated on: Wed, 20 February 2013 04:16]

Report message to a moderator

Re: Cached Map Update NPE on element remove [message #1017175 is a reply to message #1011408] Sun, 10 March 2013 10:52 Go to previous messageGo to next message
Cristian Oancea is currently offline Cristian Oancea
Messages: 2
Registered: February 2013
Junior Member
Caused by: java.lang.NullPointerException
at java.util.Hashtable.hash(Hashtable.java:262)
at java.util.Hashtable.remove(Hashtable.java:585)
at org.eclipse.persistence.indirection.IndirectMap.remove(IndirectMap.java:600)
at org.eclipse.persistence.indirection.IndirectMap.remove(IndirectMap.java:600)
at org.eclipse.persistence.internal.queries.MapContainerPolicy.removeFrom(MapContainerPolicy.java:731)
at org.eclipse.persistence.internal.queries.ContainerPolicy.mergeChanges(ContainerPolicy.java:1087)
at org.eclipse.persistence.internal.queries.ContainerPolicy.mergeChanges(ContainerPolicy.java:1071)
at org.eclipse.persistence.mappings.CollectionMapping.mergeChangesIntoObject(CollectionMapping.java:1374)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.mergeChangesIntoObject(ObjectBuilder.java:3484)
at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfWorkingCopyIntoOriginal(MergeManager.java:876)
at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfWorkingCopyIntoOriginal(MergeManager.java:687)
at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(MergeManager.java:307)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeChangesIntoParent(UnitOfWorkImpl.java:3260)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeChangesIntoParent(RepeatableWriteUnitOfWork.java:369)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitRootUnitOfWork(RepeatableWriteUnitOfWork.java:283)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitAndResume(UnitOfWorkImpl.java:1147)
at org.eclipse.persistence.internal.jpa.transaction.EntityTransactionImpl.commitInternal(EntityTransactionImpl.java:84)
... 32 more#
Re: Cached Map Update NPE on element remove [message #1021081 is a reply to message #1017175] Tue, 19 March 2013 09:54 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This could be a bug in @MapKeyColumn, please log the bug with detailed information and test if possible.

Your model does not seem like it should be using a @MapKeyColumn though, you should just use a @MapKey as the name is contained in the Child object.
You could also not use a Map to workaround the issue.

See,
http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Maps


James : Wiki : Book : Blog : Twitter
Previous Topic:IllegalArgument Exception using a Enum as Query Parameter
Next Topic:@JoinFetch doesn't work with mappings on Embeddables
Goto Forum:
  


Current Time: Thu Aug 21 20:09:21 EDT 2014

Powered by FUDForum. Page generated in 0.04174 seconds