我使用带有hibernate的条件API;
当我使用像[1]这样的entitymanager时,我得到以下异常
[1]
@PersistenceContext
private EntityManager em;
public void update(Tank entity) {
Tank item = em.getReference(Tank.class,entity.getId());
if (entity.getManufacturerId()!=null) {
item.setManufacturer(em.getReference(Manufacturer.class , entity.getManufacturerId()));
item.setManufacturerId(entity.getManufacturerId());
}
..
}
10/24/2016 2:01:21 PM[0m[33m03:01:21,516 WARN [com.arjuna.ats.arjuna] (default task-6) ARJUNA012125: TwoPhaseCoordinator.beforeCompletion - failed for SynchronizationImple< 0:ffffac110002:20c34f5a:580d4ee1:3b50bb, org.jboss.as.txn.service.internal.tsr.JCAOrderedLastSynchronizationList@70266c0e >: javax.persistence.OptimisticLockException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
10/24/2016 2:01:21 PM at org.hibernate.internal.ExceptionConverterImpl.wrapStaleStateException(ExceptionConverterImpl.java:212)
10/24/2016 2:01:21 PM at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:86)
10/24/2016 2:01:21 PM at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
10/24/2016 2:01:21 PM at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
10/24/2016 2:01:21 PM at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1403)
10/24/2016 2:01:21 PM at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:473)
10/24/2016 2:01:21 PM at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3133)
10/24/2016 2:01:21 PM at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2370)
10/24/2016 2:01:21 PM at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
10/24/2016 2:01:21 PM at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.beforeCompletion(JtaTransactionCoordinatorImpl.java:320)
10/24/2016 2:01:21 PM at org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:47)
10/24/2016 2:01:21 PM at org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:37)
10/24/2016 2:01:21 PM at org.jboss.as.txn.service.internal.tsr.JCAOrderedLastSynchronizationList.beforeCompletion(JCAOrderedLastSynchronizationList.java:116)
10/24/2016 2:01:21 PM at com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple.beforeCompletion(SynchronizationImple.java:76)
10/24/2016 2:01:21 PM at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.beforeCompletion(TwoPhaseCoordinator.java:368)
10/24/2016 2:01:21 PM at com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.end(TwoPhaseCoordinator.java:91)
10/24/2016 2:01:21 PM at com.arjuna.ats.arjuna.AtomicAction.commit(AtomicAction.java:162)
10/24/2016 2:01:21 PM at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1200)
10/24/2016 2:01:21 PM at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:126)
10/24/2016 2:01:21 PM at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:89)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:91)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:279)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:327)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:47)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.deployment.processors.StartupAwaitInterceptor.processInvocation(StartupAwaitInterceptor.java:22)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:437)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptor.processInvocation(ContainerManagedConcurrencyInterceptor.java:110)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:67)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:54)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
10/24/2016 2:01:21 PM at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:636)
10/24/2016 2:01:21 PM at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)
10/24/2016 2:01:21 PM at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
10/24/2016 2:01:21 PM at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:198)
10/24/2016 2:01:21 PM at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:185)
10/24/2016 2:01:21 PM at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
10/24/2016 2:01:21 PM at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
10/24/2016 2:01:21 PM at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:73)
10/24/2016 2:01:21 PM at com.leightonobrien.lob2.rest.autogen.TankEndpoint$$$view1.update(Unknown Source)
10/24/2016 2:01:21 PM at sun.reflect.GeneratedMethodAccessor348.invoke(Unknown Source)
10/24/2016 2:01:21 PM at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
10/24/2016 2:01:21 PM at java.lang.reflect.Method.invoke(Method.java:498)
10/24/2016 2:01:21 PM at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:433)
10/24/2016 2:01:21 PM at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:128)
10/24/2016 2:01:21 PM at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
10/24/2016 2:01:21 PM at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
10/24/2016 2:01:21 PM at com.leightonobrien.lob2.rest.autogen.TankEndpoint$Proxy$_$$_Weld$EnterpriseProxy$.update(Unknown Source)
10/24/2016 2:01:21 PM at sun.reflect.GeneratedMethodAccessor428.invoke(Unknown Source)
10/24/2016 2:01:21 PM at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
10/24/2016 2:01:21 PM at java.lang.reflect.Method.invoke(Method.java:498)
10/24/2016 2:01:21 PM at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
10/24/2016 2:01:21 PM at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)
10/24/2016 2:01:21 PM at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249)
10/24/2016 2:01:21 PM at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)
10/24/2016 2:01:21 PM at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)
10/24/2016 2:01:21 PM at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:209)
10/24/2016 2:01:21 PM at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)
10/24/2016 2:01:21 PM at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
10/24/2016 2:01:21 PM at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
10/24/2016 2:01:21 PM at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
10/24/2016 2:01:21 PM at com.cdi.crud.infra.filter.ApplicationFilter.doFilter(ApplicationFilter.java:54)
10/24/2016 2:01:21 PM at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:84)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
10/24/2016 2:01:21 PM at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
10/24/2016 2:01:21 PM at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10/24/2016 2:01:21 PM at org.keycloak.adapters.undertow.UndertowAuthenticatedActionsHandler.handleRequest(UndertowAuthenticatedActionsHandler.java:66)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
10/24/2016 2:01:21 PM at io.undertow.server.handlers.DisableCacheHandler.handleRequest(DisableCacheHandler.java:33)
10/24/2016 2:01:21 PM at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10/24/2016 2:01:21 PM at io.undertow.security.handlers.AuthenticationConstraintHandler.handleRequest(AuthenticationConstraintHandler.java:53)
10/24/2016 2:01:21 PM at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.security.ServletSecurityConstraintHandler.handleRequest(ServletSecurityConstraintHandler.java:59)
10/24/2016 2:01:21 PM at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
10/24/2016 2:01:21 PM at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
10/24/2016 2:01:21 PM at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
10/24/2016 2:01:21 PM at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10/24/2016 2:01:21 PM at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
10/24/2016 2:01:21 PM at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10/24/2016 2:01:21 PM at org.keycloak.adapters.undertow.ServletPreAuthActionsHandler.handleRequest(ServletPreAuthActionsHandler.java:69)
10/24/2016 2:01:21 PM at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
10/24/2016 2:01:21 PM at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
10/24/2016 2:01:21 PM at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
10/24/2016 2:01:21 PM at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10/24/2016 2:01:21 PM at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10/24/2016 2:01:21 PM at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10/24/2016 2:01:21 PM at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10/24/2016 2:01:21 PM at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10/24/2016 2:01:21 PM at io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
10/24/2016 2:01:21 PM at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
10/24/2016 2:01:21 PM at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
10/24/2016 2:01:21 PM at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
10/24/2016 2:01:21 PM at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
10/24/2016 2:01:21 PM at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
10/24/2016 2:01:21 PM at java.lang.Thread.run(Thread.java:745)