当我尝试使用jpa执行实体管理器的查询时,我收到以下异常。 看来我遇到了jta配置问题,但我不确定。 我正在使用带有java ee 5应用程序的quartz,并且我在webpshere服务器中运行。
E org.hibernate.ejb.AbstractEntityManagerImpl handlePersistenceException Unable to mark for rollback on PersistenceException:
org.hibernate.HibernateException: javax.naming.ConfigurationException: A JNDI operation on a "java:" name cannot be completed because the server runtime is not able to associate the operation's thread with any J2EE application component.
This condition can occur when the JNDI client using the "java:" name is not executed on the thread of a server application request. Make sure that a J2EE application does not execute JNDI operations on "java:" names within static code blocks or in threads created by that J2EE application. Such code does not necessarily run on the thread of a server application request and therefore is not supported by JNDI operations on "java:" names. [Root exception is javax.naming.NameNotFoundException: Name comp/websphere not found in context "java:".]
at
org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.<init>(WebSphereExtendedJTATransactionLookup.java:188)
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.<init>(WebSphereExtendedJTATransactionLookup.java:178)
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter.getTransaction(WebSphereExtendedJTATransactionLookup.java:140)
at org.hibernate.ejb.transaction.JoinableCMTTransaction.isTransactionInProgress(JoinableCMTTransaction.java:64)
at org.hibernate.ejb.transaction.JoinableCMTTransaction.tryJoiningTransaction(JoinableCMTTransaction.java:78)
at org.hibernate.ejb.transaction.JoinableCMTTransactionFactory.isTransactionInProgress(JoinableCMTTransactionFactory.java:51)
at org.hibernate.jdbc.JDBCContext.isTransactionInProgress(JDBCContext.java:235)
at org.hibernate.jdbc.JDBCContext.registerSynchronizationIfPossible(JDBCContext.java:200)
at org.hibernate.impl.SessionImpl.checkTransactionSynchStatus(SessionImpl.java:2112)
at org.hibernate.impl.SessionImpl.getSessionFactory(SessionImpl.java:1853)
at org.hibernate.ejb.AbstractEntityManagerImpl.markAsRollback(AbstractEntityManagerImpl.java:1123)
at org.hibernate.ejb.AbstractEntityManagerImpl.handlePersistenceException(AbstractEntityManagerImpl.java:1296)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1390)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1317)
at org.hibernate.ejb.AbstractEntityManagerImpl.joinTransaction(AbstractEntityManagerImpl.java:1252)
at org.hibernate.ejb.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:168)
at org.hibernate.ejb.EntityManagerImpl.<init>(EntityManagerImpl.java:84)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:112)
at org.hibernate.ejb.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:107)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.invokeProxyMethod(AbstractEntityManagerFactoryBean.java:388)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean$ManagedEntityManagerFactoryInvocationHandler.invoke(AbstractEntityManagerFactoryBean.java:541)
at com.sun.proxy.$Proxy521.createEntityManager(Unknown Source)
at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:285)
at com.sun.proxy.$Proxy524.createQuery(Unknown Source)
at br.com.vr.platpedidos.infrastructure.pedido.persistence.PedidoORMRepositoryImpl.buscarReferencia(PedidoORMRepositoryImpl.java:44)
at br.com.vr.platpedidos.application.pedido.repository.PedidoRepositoryImpl.buscarModalidadeProdutoDoPedido(PedidoRepositoryImpl.java:29)
at br.com.vr.platpedidos.application.pedido.services.PedidoApplicationServiceImpl.obterModalidadeDeProdutoDoPedido(PedidoApplicationServiceImpl.java:42)
at br.com.vr.platpedidos.application.facade.PlatpedidosFacadeImpl.obterModalidadeDeProduto(PlatpedidosFacadeImpl.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85)
at br.com.vr.platpedidos.infrastructure.exception.ExceptionLoggingAspect.logException(ExceptionLoggingAspect.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy540.obterModalidadeDeProduto(Unknown Source)
at br.com.vr.platpedidos.orquestracao.infrastructure.PlataformaDePedidosGateway.obterModalidadeDeProduto(PlataformaDePedidosGateway.java:60)
at br.com.vr.platpedidos.orquestracao.application.OrquestracaoApplicationServiceImpl.importarArquivosDePedido(OrquestracaoApplicationServiceImpl.java:40)
at br.com.vr.platpedidos.orquestracao.facade.OrquestracaoFacadeImpl.importarArquivosDePedido(OrquestracaoFacadeImpl.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:269)
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:257)
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:75)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
答案 0 :(得分:0)
您在错误消息和堆栈跟踪中有详细的答案:
ConfigurationException:&#34; java上的JNDI操作:&#34;名字不能 已完成,因为服务器运行时无法关联 任何J2EE应用程序组件的操作线程。 :此 当JNDI客户端使用&#34; java时出现条件:&#34;名字不是 在服务器应用程序请求的线程上执行。
以下:
org.quartz.simpl.SimpleThreadPool上的org.quartz.core.JobRunShell.run (JobRunShell.java:202)$ WorkerThread.run(SimpleThreadPool.java:573)
如果您使用的是WebSphere Liberty,则可以使用例如ejbTimers或managedThreads替换quartz,或者将JNDI更改为全局名称。
在Java EE应用程序中不建议使用quartz,因为它会创建非托管线程。
答案 1 :(得分:0)
我刚刚在以下帖子中找到答案: http://gybas.com/2014/quartz-websphere-spring/