users@glassfish.java.net

Re: problem removing entity

From: Daniel Cavalcanti <dhcavalcanti_at_gmail.com>
Date: Mon, 18 Jun 2007 14:14:08 -0400

I'll try that.
thanks!

On 6/18/07, Gordon Yorke <gordon.yorke_at_oracle.com> wrote:
>
> As the exception states the object passed to remove must be a managed
> entity, update your destroy method to look like this:
>
> public void destroy(Unit unit) {
> Unit managedUnit = em.merge(unit);
> em.remove(managedUnit);
> }
> Also, is this 'Unit' class involved in any relationships? If so, the
> application is responcible for removing these relationships prior to
> deleting this entity. There is no relationship maintenance in JPA.
> --Gordon
>
> -----Original Message-----
> *From:* Daniel Cavalcanti [mailto:dhcavalcanti_at_gmail.com]
> *Sent:* Saturday, June 16, 2007 12:39 PM
> *To:* glassfish
> *Subject:* problem removing entity
>
> Hi...
> I'm trying to remove an entity from a app-client that calls a session bean
> (facade pattern) to carry the removal.
>
> In the session bean, the relevant parts of code follow:
>
> @PersistenceContext()
> private EntityManager em;
>
> public void destroy(Unit unit) {
> em.merge(unit);
> em.remove(unit);
> }
>
> However, I'm getting this exception -- trace retrieved from java web start
> console:
>
> Exception in thread "AWT-EventQueue-2" javax.ejb.EJBException: nested
> exception is: java.rmi.ServerException: RemoteException occurred in server
> thread; nested exception is:
> java.rmi.RemoteException : null; nested exception is:
> java.lang.IllegalArgumentException: Entity must be managed to call
> remove: 123 Foo Road, Bar City, FL 33300, try merging the detached and try
> the remove again.
> java.rmi.ServerException : RemoteException occurred in server thread;
> nested exception is:
> java.rmi.RemoteException: null; nested exception is:
> java.lang.IllegalArgumentException: Entity must be managed to call
> remove: 123 Foo Road, Bar City, FL 33300, try merging the detached and try
> the remove again.
> at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(
> Util.java:203)
> at
> com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.privateInvoke
> (StubInvocationHandlerImpl.java:176)
> at
> com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(
> StubInvocationHandlerImpl.java:123)
> at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(
> BCELStubBase.java:196)
> at
> com.playground.concierge.model.facade.__UnitFacadeRemote_Remote_DynamicStub.destroy(com/playground/concierge/model/facade/__UnitFacadeRemote_Remote_DynamicStub.java)
> at
> com.playground.concierge.model.facade._UnitFacadeRemote_Wrapper.destroy(com/playground/concierge/model/facade/_UnitFacadeRemote_Wrapper.java)
>
> at
> com.playground.concierge.manager.ConciergeManager.unitsRemoveButtonActionPerformed
> (ConciergeManager.java:334)
> at com.playground.concierge.manager.ConciergeManager.access$200(
> ConciergeManager.java:15)
> at com.playground.concierge.manager.ConciergeManager$3.actionPerformed
> (ConciergeManager.java:91)
> at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
> at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
> at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> at javax.swing.plaf.basic.BasicButtonListener.mouseReleased (Unknown
> Source)
> at java.awt.Component.processMouseEvent(Unknown Source)
> at javax.swing.JComponent.processMouseEvent(Unknown Source)
> at java.awt.Component.processEvent(Unknown Source)
> at java.awt.Container.processEvent (Unknown Source)
> at java.awt.Component.dispatchEventImpl(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.LightweightDispatcher.retargetMouseEvent (Unknown Source)
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Window.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
> at java.awt.EventDispatchThread.pumpOneEventForFilters (Unknown
> Source)
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.run(Unknown Source)
> Caused by: java.rmi.RemoteException: null; nested exception is:
> java.lang.IllegalArgumentException : Entity must be managed to call
> remove: 123 Foo Road, Bar City, FL 33300, try merging the detached and try
> the remove again.
> at com.sun.enterprise.iiop.POAProtocolMgr.mapException(
> POAProtocolMgr.java:251)
> at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java
> :1375)
> at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java
> :1305)
> at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke (
> EJBObjectInvocationHandler.java:210)
> at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(
> EJBObjectInvocationHandlerDelegate.java:117)
> at $Proxy72.destroy(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:125)
> at
> com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant
> (CorbaServerRequestDispatcherImpl.java :658)
> at
> com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(
> CorbaServerRequestDispatcherImpl.java:198)
> at
> com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest
> (CorbaMessageMediatorImpl.java :1820)
> at
> com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(
> CorbaMessageMediatorImpl.java:1680)
> at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput
> (CorbaMessageMediatorImpl.java :1062)
> at
> com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback
> (RequestMessage_1_2.java:194)
> at
> com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(
> CorbaMessageMediatorImpl.java :780)
> at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(
> CorbaMessageMediatorImpl.java:537)
> at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(
> CorbaMessageMediatorImpl.java:2541)
> at
> com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(
> ThreadPoolImpl.java:524)
> Caused by: java.lang.IllegalArgumentException: Entity must be managed to
> call remove: 123 Foo Road, Bar City, FL 33300, try merging the detached and
> try the remove again.
> at
> oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.performRemove(
> UnitOfWorkImpl.java:2781)
> at
> oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl.remove(
> EntityManagerImpl.java:253)
> at com.sun.enterprise.util.EntityManagerWrapper.remove(
> EntityManagerWrapper.java:512)
> at com.playground.concierge.model.facade.UnitFacade.destroy(
> UnitFacade.java:49)
> 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:2884)
> at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java
> :3975)
> at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(
> EJBObjectInvocationHandler.java:203)
> ... 17 more
> javax.ejb.EJBException: nested exception is: java.rmi.ServerException:
> RemoteException occurred in server thread; nested exception is:
> java.rmi.RemoteException: null; nested exception is:
> java.lang.IllegalArgumentException : Entity must be managed to call
> remove: 123 Foo Road, Bar City, FL 33300, try merging the detached and try
> the remove again.
> at
> com.playground.concierge.model.facade._UnitFacadeRemote_Wrapper.destroy(com/playground/concierge/model/facade/_UnitFacadeRemote_Wrapper.java)
>
> at
> com.playground.concierge.manager.ConciergeManager.unitsRemoveButtonActionPerformed
> (ConciergeManager.java:334)
> at com.playground.concierge.manager.ConciergeManager.access$200(
> ConciergeManager.java:15)
> at com.playground.concierge.manager.ConciergeManager$3.actionPerformed
> (ConciergeManager.java:91)
> at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
> at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
> at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
> at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
> at javax.swing.plaf.basic.BasicButtonListener.mouseReleased (Unknown
> Source)
> at java.awt.Component.processMouseEvent(Unknown Source)
> at javax.swing.JComponent.processMouseEvent(Unknown Source)
> at java.awt.Component.processEvent(Unknown Source)
> at java.awt.Container.processEvent (Unknown Source)
> at java.awt.Component.dispatchEventImpl(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.LightweightDispatcher.retargetMouseEvent (Unknown Source)
> at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
> at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
> at java.awt.Container.dispatchEventImpl(Unknown Source)
> at java.awt.Window.dispatchEventImpl(Unknown Source)
> at java.awt.Component.dispatchEvent(Unknown Source)
> at java.awt.EventQueue.dispatchEvent(Unknown Source)
> at java.awt.EventDispatchThread.pumpOneEventForFilters (Unknown
> Source)
> at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
> at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
> at java.awt.EventDispatchThread.run(Unknown Source)
>
>