-1

I developing an application using Standard JPA and db2 and I faced the following :

I have the following classes structure:

The Parent class:

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TYPE")
@DiscriminatorValue(value="PARTY")
public class Party extends AbstractAuditableObject implements Serializable {
}

The Child Class:

@Entity
@DiscriminatorValue(value="PERSON")
public class Person extends Party implements Serializable {
}

And I create a Party of type Person and saved it and then while updating it i got the following exception:

org.apache.openjpa.persistence.EntityNotFoundException: Attempted to attach instance "12" of type "class com.ibm.sa.Party.domain.Party", but this instance is already in the datastore as type "class com.ibm.sa.kap.Shape.model.Person".
at org.apache.openjpa.kernel.VersionAttachStrategy.attach(VersionAttachStrategy.java:118) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]
at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:251) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]
at org.apache.openjpa.kernel.AttachManager.attach(AttachManager.java:104) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]
at org.apache.openjpa.kernel.BrokerImpl.attach(BrokerImpl.java:3447) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]
at org.apache.openjpa.kernel.DelegatingBroker.attach(DelegatingBroker.java:1214) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]
at org.apache.openjpa.persistence.EntityManagerImpl.merge(EntityManagerImpl.java:877) ~[com.ibm.ws.jpa.jar:1.0.1-SNAPSHOT]
at com.ibm.ws.jpa.management.JPAExEmInvocation.merge(JPAExEmInvocation.java:305) ~[com.ibm.ws.runtime.jar:na]
at com.ibm.ws.jpa.management.JPAEntityManager.merge(JPAEntityManager.java:156) ~[com.ibm.ws.runtime.jar:na]
at com.ibm.sa.kap.dao.PartyDAO.updateParty(PartyDAO.java:56) ~[KAPDataAccess.jar:na]
at com.ibm.sa.kap.domain.party.EJSLocal1SLPartyDAO_b691ea75.updateParty(EJSLocal1SLPartyDAO_b691ea75.java) [na:na]
at com.ibm.sa.kap.domain.party.EditPartyService.updateParty(EditPartyService.java:45) [KAPDomain.jar:na]
at com.ibm.sa.kap.domain.party.EJSLocal1SLEditPartyService_8f3f6222.updateParty(EJSLocal1SLEditPartyService_8f3f6222.java) [na:na]
at com.ibm.sa.kap.application.bean.EditPartyApplication.updateParty(EditPartyApplication.java:72) [KAPApplication.jar:na]
at com.ibm.sa.kap.application.client.EJSLocal1SLEditPartyApplication_aa9d77c4.updateParty(EJSLocal1SLEditPartyApplication_aa9d77c4.java) [na:na]
at com.ibm.sa.kap.ui.controller.CreatePartyController.save(CreatePartyController.java:385) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:48) ~[na:1.6.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) ~[na:1.6.0]
at java.lang.reflect.Method.invoke(Method.java:600) ~[na:1.6.0]
at org.apache.el.parser.AstValue.invoke(AstValue.java:268) [com.ibm.ws.webcontainer.jar:na]
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [com.ibm.ws.webcontainer.jar:na]
at org.apache.myfaces.view.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:83) [com.ibm.ws.jsf.myfaces.jar:na]
at javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBinding.java:88) [javax.j2ee.jsf.jar:na]
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:100) [com.ibm.ws.jsf.myfaces.jar:na]
at javax.faces.component.UICommand.broadcast(UICommand.java:120) [javax.j2ee.jsf.jar:na]
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:973) [javax.j2ee.jsf.jar:na]
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:275) [javax.j2ee.jsf.jar:na]
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1285) [javax.j2ee.jsf.jar:na]
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:711) [javax.j2ee.jsf.jar:na]
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:34) [com.ibm.ws.jsf.myfaces.jar:na]
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171) [com.ibm.ws.jsf.myfaces.jar:na]
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [com.ibm.ws.jsf.myfaces.jar:na]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189) [javax.j2ee.jsf.jar:na]
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1225) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:775) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:457) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.sa.kap.common.web.filter.CustomHeadersFilter.doFilter(CustomHeadersFilter.java:24) [KAPCommon.jar:na]
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.sa.kap.ui.attachment.filter.WebSphereFileUploadFilter.doFilter(WebSphereFileUploadFilter.java:87) [classes/:na]
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:928) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1025) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:908) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195) [com.ibm.ws.webcontainer.jar:na]
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:277) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214) [na:CCX.CF [o1103.02]]
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113) [na:CCX.CF [o1103.02]]
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:166) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) [com.ibm.ws.runtime.jar:na]
at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) [com.ibm.ws.runtime.jar:na]
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1691) [com.ibm.ws.runtime.jar:na]

P.S.: The scenario is working fine if creating a Party of type Party.

Could you please advice how to solve this problem?

Thanks in advance

mustaccio
  • 18,234
  • 16
  • 48
  • 57
User
  • 573
  • 3
  • 15
  • 28
  • 1
    Where is your code? How can we fix it without seeing it? – JB Nizet Aug 14 '13 at 17:55
  • I don't understand what you mean by create a Party of type Person - it is a Person or it is a Party. Are you creating an instance of Party and giving it an ID of something saved to the database as a person? If so, this isn't allowed and you should get an exception such as this. – Chris Aug 14 '13 at 18:17

1 Answers1

0

How are you assigning Ids? From the error sounds to me that you are trying to persist an object with an id that already exists. In that case make sure you use the merge method if you are updating, or double check how you are generating your ids, and avoid setting a different strategy on the subclass (would really help to see the whole code for your classes).

Jido
  • 1