[ 
https://issues.apache.org/jira/browse/OFBIZ-6808?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Swapnil M Mane updated OFBIZ-6808:
----------------------------------
    Attachment: OFBIZ-6808.patch

> Calling Groovy as Event generates error when delegator.find used
> ----------------------------------------------------------------
>
>                 Key: OFBIZ-6808
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-6808
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: Trunk, Upcoming Branch
>            Reporter: Swapnil M Mane
>         Attachments: OFBIZ-6808.patch
>
>
> We are using Groovy as event in the controller request, everything works fine 
> for us but as we used delegator.find()
> it generates the following error
> -----------------------------------------------------------------------------------------------------------------------------------------------------------
> ERROR: Cannot do a find that returns an EntityListIterator with no 
> transaction in place. Wrap this call in a transaction.
>      [java] java.lang.Exception: Stack Trace
>      [java]   at 
> org.ofbiz.entity.GenericDelegator.find(GenericDelegator.java:1757) 
> [ofbiz-entity.jar:?]
>      [java]   at org.ofbiz.entity.Delegator$find.call(Unknown Source) 
> [ofbiz-entity.jar:?]
>      [java]   at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> ProductInventory$_run_closure1.doCall(ProductInventory.groovy:18) [script:?]
>      [java]   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
> ~[?:1.8.0_60]
>      [java]   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
> ~[?:1.8.0_60]
>      [java]   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>  ~[?:1.8.0_60]
>      [java]   at java.lang.reflect.Method.invoke(Method.java:497) 
> ~[?:1.8.0_60]
>      [java]   at 
> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90) 
> [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233) 
> [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909) 
> [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at groovy.lang.Closure.call(Closure.java:423) 
> [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at groovy.lang.Closure.call(Closure.java:439) 
> [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1324)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:1296)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at org.codehaus.groovy.runtime.dgm$147.invoke(Unknown Source) 
> [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:271)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:53)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
>  [groovy-all-2.2.1.jar:2.2.1]
>      [java]   at ProductInventory.run(ProductInventory.groovy:11) [script:?]
>      [java]   at 
> org.ofbiz.webapp.event.GroovyEventHandler.invoke(GroovyEventHandler.java:107) 
> [ofbiz-webapp.jar:?]
>      [java]   at 
> org.ofbiz.webapp.control.RequestHandler.runEvent(RequestHandler.java:763) 
> [ofbiz-webapp.jar:?]
>      [java]   at 
> org.ofbiz.webapp.control.RequestHandler.doRequest(RequestHandler.java:476) 
> [ofbiz-webapp.jar:?]
>      [java]   at 
> org.ofbiz.webapp.control.ControlServlet.doGet(ControlServlet.java:210) 
> [ofbiz-webapp.jar:?]
>      [java]   at 
> org.ofbiz.webapp.control.ControlServlet.doPost(ControlServlet.java:89) 
> [ofbiz-webapp.jar:?]
>      [java]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) 
> [servlet-api-3.0.jar:?]
>      [java]   at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) 
> [servlet-api-3.0.jar:?]
>      [java]   at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
>  [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>  [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.ofbiz.webapp.control.ContextFilter.doFilter(ContextFilter.java:349) 
> [ofbiz-webapp.jar:?]
>      [java]   at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
>  [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
>  [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
>  [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
>  [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
>  [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) 
> [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 
> [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
>  [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) 
> [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) 
> [tomcat-7.0.65-catalina.jar:7.0.65]
>      [java]   at 
> org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
>  [tomcat-7.0.65-tomcat-coyote.jar:7.0.65]
>      [java]   at 
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
>  [tomcat-7.0.65-tomcat-coyote.jar:7.0.65]
>      [java]   at 
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
>  [tomcat-7.0.65-tomcat-coyote.jar:7.0.65]
>      [java]   at 
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>  [?:1.8.0_60]
>      [java]   at 
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>  [?:1.8.0_60]
>      [java]   at 
> org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
>  [tomcat-7.0.65-tomcat-coyote.jar:7.0.65]
>      [java]   at java.lang.Thread.run(Thread.java:745) [?:1.8.0_60]
> -----------------------------------------------------------------------------------------------------------------------------------------------------------
> Reason: 
> Since we are using find method of GenericDelegator.java
> As per the code implementation it required the transaction should exist 
>    if (!TransactionUtil.isTransactionInPlace()) {
> if not, it generate error
>     ERROR: Cannot do a find that returns an EntityListIterator with no 
> transaction in place. Wrap this call in a transaction.
> -----------------------------------------------------------------------------------------------------------------------------------------------------------
> Possible Solution:
> The one possible solution could be to initialize the transaction when the 
> groovy is called as event and commit the transaction after the completion.
> The following code base at the starting and ending of GroovyEventHandler.java 
> can resolve the issue.
>    // At begining
>     boolean beganTransaction = false;
>     if (!TransactionUtil.isTransactionInPlace()) { 
>         beganTransaction = TransactionUtil.begin(); 
>     }
>    // At End
>    if (beganTransaction) { 
>        TransactionUtil.commit(); 
>    }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to