Loading persistent CFC within transaction throws error

Description

I'm getting an error "can't use different connections to the same datasource inside a single transaction" whenever I attempt to load a persistent CFC within a transaction to populate and then save it. This works for me on both ACF 11 and Lucee 4.5.2.018 but not Lucee 5. In the Admin panel for the datasource, I tried to set "Connection limit (max)" to 1, but this did not resolve the issue. Unfortunately, it prevents me from testing large portions of the codebase at this time. Code snippet below:

transaction {
if ( StructKeyExists(rc, "qualityControlId") && IsNumeric( rc.qualityControlId ) ) {
var qc = entityLoadByPk( 'QualityControl', rc.qualityControlId );
} else {
var qc = entityNew( 'QualityControl' );
}

...
}

The error is thrown with both entityLoadByPk() and entityNew(), exactly at those lines, depending on whether it is an edit or not.

If the entity is created outside of the transaction, the error does not seem to occur.

For completeness, here is how the QualityControl entity is defined, but the same error occurs for other entities as well:

component output="false" persistent="true" extends="AbstractEntity"
{
property
name="qualityControlId"
type="numeric"
fieldtype="id"
datatype="integer"
generator="identity";
property name="qcDate" sqltype="datetime";
property name="floor" sqltype="tinyint";
property name="comment" sqltype="text";
property name="isTemplate" sqltype="tinyint";
property name="templateName" sqltype="varchar" length="50";

property name="employee"
fieldtype="many-to-one"
cfc="Employee"
fkcolumn="employeeId"
lazy="false"
missingrowIgnored="true";

property name="user"
fieldtype="many-to-one"
cfc="User"
fkcolumn="userId"
lazy="true"
missingrowIgnored="true";

property name="location"
fieldtype="many-to-one"
cfc="Location"
fkcolumn="locationId"
lazy="true"
missingrowIgnored="true";

property name="qualityControlRegions"
fieldtype="one-to-many"
cfc="QualityControlRegion"
type="array"
singularname="qualityControlRegion"
fkcolumn="qualityControlId"
cascade="delete-orphan"
orderby="sortOrder";

}

Here's the stacktrace I see with this error:

lucee.runtime.exp.DatabaseException: can't use different connections to the same datasource inside a single transaction at lucee.runtime.db.DatasourceManagerImpl._add(DatasourceManagerImpl.java:135) at lucee.runtime.db.DatasourceManagerImpl.add(DatasourceManagerImpl.java:114) at lucee.runtime.PageContextImpl.getORMSession(PageContextImpl.java:3123) at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:57) at lucee.runtime.orm.ORMUtil.getSession(ORMUtil.java:53) at lucee.runtime.functions.orm.EntityLoadByPK.call(EntityLoadByPK.java:28) at pulical.controllers.qc_cfc$cf.udfCall(/Users/nando/sites/pulical/controllers/qc.cfc:44) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:105) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:337) at lucee.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:208) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:698) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:580) at lucee.runtime.ComponentImpl.callWithNamedValues(ComponentImpl.java:1919) at lucee.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:793) at lucee.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:786) at lucee.runtime.util.VariableUtilImpl.callFunction(VariableUtilImpl.java:736) at lucee.runtime.interpreter.ref.func.UDFCall.getValue(UDFCall.java:65) at lucee.runtime.interpreter.CFMLExpressionInterpreter.interpret(CFMLExpressionInterpreter.java:214) at lucee.runtime.functions.dynamicEvaluation.Evaluate._call(Evaluate.java:109) at lucee.runtime.functions.dynamicEvaluation.Evaluate.call(Evaluate.java:102) at lucee.runtime.functions.dynamicEvaluation.Evaluate.call(Evaluate.java:43) at pulical.framework.one_cfc$cf.udfCall8(/Users/nando/sites/pulical/framework/one.cfc:1412) at pulical.framework.one_cfc$cf.udfCall(/Users/nando/sites/pulical/framework/one.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:105) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:337) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:222) at lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:770) at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:752) at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1584) at pulical.framework.one_cfc$cf.udfCall5(/Users/nando/sites/pulical/framework/one.cfc:816) at pulical.framework.one_cfc$cf.udfCall(/Users/nando/sites/pulical/framework/one.cfc) at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:105) at lucee.runtime.type.UDFImpl._call(UDFImpl.java:337) at lucee.runtime.type.UDFImpl.call(UDFImpl.java:222) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:697) at lucee.runtime.ComponentImpl._call(ComponentImpl.java:580) at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1902) at lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:422) at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:224) at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:43) at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2266) at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2258) at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2226) at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:741) at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:102) at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:62) at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1085) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1556) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1513) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

Environment

5.0.0.195-SNAPSHOT
OSX 10.10.5
MySql 5.5

Activity

Show:
Pothys - MitrahSoft
February 16, 2018, 10:44 AM

I've tested with latest version of lucee. Issue seems fixed on lucee 5.0.0.223 version. So I close this ticket .

Fixed

Assignee

Michael Offner

Reporter

Nando

Priority

New

Labels

Fix versions

Affects versions

Configure