-1

標準JPAとdb2を使用してアプリケーションを開発しましたが、次のことに直面しました。

私は次のクラス構造を持っています:

親クラス:

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

子クラス:

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

そして、タイプ Person の Party を作成して保存しましたが、更新中に次の例外が発生しました。

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]

PS: パーティ タイプのパーティを作成する場合、シナリオは正常に機能しています。

この問題を解決する方法を教えてください。

前もって感謝します

4

1 に答える 1

0

どのように ID を割り当てていますか? エラー音から、既に存在する ID を持つオブジェクトを永続化しようとしているように聞こえます。その場合、更新する場合は必ず merge メソッドを使用するか、ID の生成方法を再確認し、サブクラスに別の戦略を設定しないようにしてください (クラスのコード全体を確認するのに本当に役立ちます)。

于 2013-08-15T01:19:32.700 に答える