users@glassfish.java.net

NPE in Toplink when persisting a _at_OneToMany w/_at_MapKey

From: <glassfish_at_javadesktop.org>
Date: Tue, 21 Aug 2007 10:36:12 PDT

I just filed https://glassfish.dev.java.net/issues/show_bug.cgi?id=3515; I'm getting a <tt>NullPointerException</tt> from Toplink when I try to <tt>merge()</tt> an <tt>@Entity</tt> with a <tt>@OneToMany</tt> relationship that is qualified with a <tt>@MapKey</tt>.

The code that I added that's problematic:
<blockquote>[code] @OneToMany(mappedBy="partyEntity", cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
  @MapKey(name="type")
  protected Map<String, PartyNameEntity> getPartyNameEntities() {
    return this.partyNameEntities;
  }

  protected void setPartyNameEntities(final Map<String, PartyNameEntity> map) {
    this.partyNameEntities = map;
  }[/code]</blockquote>

I can supply the <tt>PartyNameEntity</tt> code as well if needed.

The stack (look for the "caused by" block):<blockquote>[code][#|2007-08-21T10:14:22.046-0400|INFO|sun-appserver9.1|javax.enterprise.system.container.ejb|_ThreadID=63;_ThreadName=p:
thread-pool-1; w: 77;|
javax.ejb.EJBException
        at
com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:3869)
        at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:3769)
        at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:3571)
        at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1354)
        at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1316)
        at
com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:210)
        at
com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:117)
        at $Proxy104.save(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:154)
        at
com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:687)
        at
com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:227)
        at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1846)
        at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1706)
        at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:1088)
        at
com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:223)
        at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:806)
        at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:563)
        at
com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2567)
        at
com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:555)
Caused by: java.lang.NullPointerException
        at java.util.Hashtable.put(Hashtable.java:399)
        at
oracle.toplink.essentials.internal.queryframework.MapContainerPolicy.addInto(MapContainerPolicy.java:123)
        at
oracle.toplink.essentials.internal.queryframework.ContainerPolicy.addInto(ContainerPolicy.java:107)
        at
oracle.toplink.essentials.mappings.CollectionMapping.mergeIntoObject(CollectionMapping.java:788)
        at
oracle.toplink.essentials.internal.descriptors.ObjectBuilder.mergeIntoObject(ObjectBuilder.java:2152)
        at
oracle.toplink.essentials.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:442)
        at
oracle.toplink.essentials.internal.sessions.MergeManager.mergeChanges(MergeManager.java:264)
        at
oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:2723)
        at
oracle.toplink.essentials.internal.ejb.cmp3.base.RepeatableWriteUnitOfWork.mergeCloneWithReferences(RepeatableWriteUnitOfWork.java:219)
        at
oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:235)
        at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.merge(EntityManagerImpl.java:128)
        at
com.sun.enterprise.util.EntityManagerWrapper.merge(EntityManagerWrapper.java:476)
        at myCode.ManagerBean.saveCore(ManagerBean.java:413)
        at myCode.ManagerBean.save(ManagerBean.java:380)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1067)
        at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:176)
        at
com.sun.ejb.containers.BaseContainer.invokeTargetBeanMethod(BaseContainer.java:2895)
        at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3986)
        at
com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:203)
        ... 17 more[/code]</blockquote>
[Message sent by forum member 'ljnelson' (ljnelson)]

http://forums.java.net/jive/thread.jspa?messageID=231852