users@glassfish.java.net

RE: EJB Transaction error with Named queries

From: Drinkwater, GJ \(Glen\) <"Drinkwater,>
Date: Wed, 22 Aug 2007 15:13:03 +0100

Hi

I had this problem with Glassfish UR1 and was asked way back to test on
glassfish V2, I have now tested this with v2 RC1 and I get the same
error.

Can anyone help???

Glen


Date: Wed, 28 Mar 2007 13:03:57 -0700
From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Content-type: text/plain; format=flowed; charset=us-ascii
Subject: EJB Transaction error with Named queries


Hi Glen,

Do you see the same behavior with the latest V2 build?

thanks,
-marina

Drinkwater, GJ (Glen) wrote:
Hi

I have a problem with transactions using glassfish UR1.

I have a web method on a ejb stateless session bean that calls a native
query and maps it to a entity class and returns the results. The query
is just a select so i dont need a tranaction and therefore i have used
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) on the
method.

The entity class lookes like


@NamedNativeQueries({
    @NamedNativeQuery(name =
"test", query= "SELECT DISTINCT ID FROM INVESTIGATION where ID = 10",
resultSetMapping="investigationMapping")
})

@SqlResultSetMappings({
@SqlResultSetMapping(name="investigationMapping",entities={_at_EntityResult
(entityClass=Investigation.class)}),
})

Now if i put this in my ejb method call the method works fine

   //Collection<Investigation> investigations =
manager.createNativeQuery(""SELECT DISTINCT ID FROM INVESTIGATION where
ID = 11915480",Investigation.class).getResultList();

but if i change it to use the NamedNativeQueries in the entity class
like this

      Collection<Investigation> investigations =
manager.createNamedQuery("test").getResultList();

I get an exception, see below for full stack trace, saying

Exception Description: Error binding to externally managed transaction
Internal Exception: java.lang.IllegalStateException: Operation not
allowed

If i annotate the method with REQUIRES_NEW the method again works.
Since this method is a select query it does not need a transaction but
when the entitymanager executes this with createNamedQuery it seems to
try to use a transaction. Why is this??

What happens differently with createNamedQuery than createNativeQuery
????


Exception Description: Error binding to externally managed transaction
Internal Exception: java.lang.IllegalStateException: Operation not
allowed
        at
oracle.toplink.essentials.exceptions.TransactionException.errorBeginning
ExternalTransaction(TransactionException.java:87)
        at
oracle.toplink.essentials.transaction.AbstractTransactionController.begi
nTransaction(AbstractTransactionController.java:125)
        at
oracle.toplink.essentials.internal.sessions.AbstractSession.beginExterna
lTransaction(AbstractSession.java:334)
        at
oracle.toplink.essentials.internal.sessions.AbstractSession.beginTransac
tion(AbstractSession.java:365)
        at
oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.beginTransact
ion(UnitOfWorkImpl.java:419)
        at
oracle.toplink.essentials.queryframework.ResultSetMappingQuery.executeDa
tabaseQuery(ResultSetMappingQuery.java:173)
        at
oracle.toplink.essentials.queryframework.DatabaseQuery.execute(DatabaseQ
uery.java:609)
        at
oracle.toplink.essentials.queryframework.DatabaseQuery.executeInUnitOfWo
rk(DatabaseQuery.java:536)
        at
oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl.internalExecu
teQuery(UnitOfWorkImpl.java:2218)
        at
oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery
(AbstractSession.java:937)
        at
oracle.toplink.essentials.internal.sessions.AbstractSession.executeQuery
(AbstractSession.java:909)
        at
oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.executeRea
dQuery(EJBQueryImpl.java:346)
        at
oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImpl.getResultL
ist(EJBQueryImpl.java:447)
        at
com.sun.enterprise.util.QueryWrapper.getResultList(QueryWrapper.java:154
)
        at uk.icat3.sessionbeans.search.Search.testThisException(Unknown
Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJB
SecurityManager.java:1050)
        at
com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:165)
        at
com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java
:3866)
        at
com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(Int
erceptorManager.java:414)
        at com.sun.ejb.Invocation.proceed(Invocation.java:373)
        at uk.icat3.sessionbeans.EJBObject.logMethods(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
com.sun.ejb.containers.interceptors.BeanAroundInvokeInterceptor$1.run(In
terceptorManager.java:523)
        at java.security.AccessController.doPrivileged(Native Method)
        at
com.sun.ejb.containers.interceptors.BeanAroundInvokeInterceptor.intercep
t(InterceptorManager.java:517)
        at
com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(Int
erceptorManager.java:414)
        at
com.sun.ejb.containers.interceptors.InterceptorManager.intercept(Interce
ptorManager.java:188)
        at
com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:3839)
        at
com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvo
cationHandler.java:147)
        at $Proxy134.testThisException(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
a:39)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
Impl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.sun.xml.ws.server.PeptTie._invoke(PeptTie.java:61)
        at
com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher.invokeEndpoint
(SOAPMessageDispatcher.java:280)
        at
com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher$SoapInvoker.in
voke(SOAPMessageDispatcher.java:588)
        at
com.sun.xml.ws.protocol.soap.server.SOAPMessageDispatcher.receive(SOAPMe
ssageDispatcher.java:147)
        at com.sun.xml.ws.server.Tie.handle(Tie.java:90)
        at
com.sun.enterprise.webservice.Ejb3MessageDispatcher.handlePost(Ejb3Messa
geDispatcher.java:160)
        at
com.sun.enterprise.webservice.Ejb3MessageDispatcher.invoke(Ejb3MessageDi
spatcher.java:89)
        at
com.sun.enterprise.webservice.EjbWebServiceServlet.dispatchToEjbEndpoint
(EjbWebServiceServlet.java:186)
        at
com.sun.enterprise.webservice.EjbWebServiceServlet.service(EjbWebService
Servlet.java:117)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
        at
com.sun.enterprise.web.AdHocContextValve.invoke(AdHocContextValve.java:1
01)
        at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java
:566)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
36)
        at
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:71)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:182)
        at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java
:566)
        at
com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipelin
e.java:120)
        at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:137)
        at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java
:566)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5
36)
        at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
        at
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
        at
com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(Pro
cessorTask.java:667)
        at
com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked
(ProcessorTask.java:574)
        at
com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(Processor
Task.java:844)
        at
com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(R
eadTask.java:287)
        at
com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:2
12)
        at
com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
        at
com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.j
ava:75)
Caused by: java.lang.IllegalStateException: Operation not allowed
        at
com.sun.ejb.containers.PMTransactionManagerImpl.begin(PMTransactionManag
erImpl.java:80)
        at
oracle.toplink.essentials.transaction.JTATransactionController.beginTran
saction_impl(JTATransactionController.java:130)
        at
oracle.toplink.essentials.transaction.AbstractTransactionController.begi
nTransaction(AbstractTransactionController.java:121)
        ... 69 more