[Coldbox 3.8.1] Base ORM Service Batch update error

Hi all,

I’ve just moved some sites from ACF over to Lucee and I’m now seeing an error that I hope someone can help me with.

I’m using the base orm services, getting and then trying to delete an entity using:

`
var notification = notificationService.get(notificationid);

if ( !isNull(notification) ) {
// Notification found - delete it
notificationService.delete(notification);
}
`

Simple stuff, but it throws this error, any ideas?

Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

And the stack trace.

{"Extended_Info":"","Message":"Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1","Detail":"","additional":{"Cause":"org.hibernate.StaleStateException"},"TagContext":[{"Raw_Trace":"system.orm.hibernate.baseormservice_cfc$cf.udfCall6(C:\\inetpub\\vhosts\\common\\coldbox\\system\\orm\\hibernate\\BaseORMService.cfc:1485)","codePrintPlain":"1483: \t\t\t}\n1484: \n1485: \t\t}\n1486: \n1487: \t\t// remove pointer, out of transaction now.\n","column":0,"line":1485,"template":"C:\\inetpub\\vhosts\\common\\coldbox\\system\\orm\\hibernate\\BaseORMService.cfc","id":"??","type":"cfml","codePrintHTML":"1483: \t\t\t}<br>\n1484: <br>\n<b>1485: \t\t}</b><br>\n1486: <br>\n1487: \t\t// remove pointer, out of transaction now.<br>\n"},{"Raw_Trace":"system.orm.hibernate.baseormservice_cfc$cf.udfCall2(C:\\inetpub\\vhosts\\common\\coldbox\\system\\orm\\hibernate\\BaseORMService.cfc:572)","codePrintPlain":"570: \t\t// using transaction closure, well, semy closures :(\n571: \t\tif( arguments.transactional ){\n572: \t\t\treturn $transactioned(variables.$delete, arguments);\n573: \t\t}\n574: \t\t$delete( argumentCollection=arguments );\n","column":0,"line":572,"template":"C:\\inetpub\\vhosts\\common\\coldbox\\system\\orm\\hibernate\\BaseORMService.cfc","id":"??","type":"cfml","codePrintHTML":"570: \t\t// using transaction closure, well, semy closures :(<br>\n571: \t\tif( arguments.transactional ){<br>\n<b>572: \t\t\treturn $transactioned(variables.$delete, arguments);</b><br>\n573: \t\t}<br>\n574: \t\t$delete( argumentCollection=arguments );<br>\n"},{"Raw_Trace":"handlers.notifications_cfc$cf.udfCall(C:\\inetpub\\vhosts\\portal.stonbury.com-CF\\handlers\\Notifications.cfc:68)","codePrintPlain":"66: \t\tif ( !isNull(notification) ) {\n67: \t\t\t// Notification found - delete it\n68: \t\t\tnotificationService.delete(notification);\n69: \t\t\tresult = true;\n70: \t\t}\n","column":0,"line":68,"template":"C:\\inetpub\\vhosts\\portal.stonbury.com-CF\\handlers\\Notifications.cfc","id":"??","type":"cfml","codePrintHTML":"66: \t\tif ( !isNull(notification) ) {<br>\n67: \t\t\t// Notification found - delete it<br>\n<b>68: \t\t\tnotificationService.delete(notification);</b><br>\n69: \t\t\tresult = true;<br>\n70: \t\t}<br>\n"},{"Raw_Trace":"system.web.controller_cfc$cf.udfCall6(C:\\inetpub\\vhosts\\common\\coldbox\\system\\web\\Controller.cfc:764)","codePrintPlain":"762: \t\t\t\t\t method=\"#arguments.method#\"\n763: \t\t\t\t\t returnvariable=\"refLocal.results\"\n764: \t\t\t\t \t argumentcollection=\"#arguments.argCollection#\">\n765: \t\t</cfif>\n766: \n","column":0,"line":764,"template":"C:\\inetpub\\vhosts\\common\\coldbox\\system\\web\\Controller.cfc","id":"??","type":"cfml","codePrintHTML":"762: \t\t\t\t\t method=&quot;#arguments.method#&quot;<br>\n763: \t\t\t\t\t returnvariable=&quot;refLocal.results&quot;<br>\n<b>764: \t\t\t\t \t argumentcollection=&quot;#arguments.argCollection#&quot;&gt;</b><br>\n765: \t\t&lt;/cfif&gt;<br>\n766: <br>\n"},{"Raw_Trace":"system.web.controller_cfc$cf.udfCall5(C:\\inetpub\\vhosts\\common\\coldbox\\system\\web\\Controller.cfc:648)","codePrintPlain":"646: \t\t\t\t\telse{\n647: \t\t\t\t\t\t// Normal execution\n648: \t\t\t\t\t\tloc.results = invoker(oHandler, ehBean.getMethod(), loc.argsMain, arguments.private);\n649: \t\t\t\t\t}\n650: \t\t\t\t}\n","column":0,"line":648,"template":"C:\\inetpub\\vhosts\\common\\coldbox\\system\\web\\Controller.cfc","id":"??","type":"cfml","codePrintHTML":"646: \t\t\t\t\telse{<br>\n647: \t\t\t\t\t\t// Normal execution<br>\n<b>648: \t\t\t\t\t\tloc.results = invoker(oHandler, ehBean.getMethod(), loc.argsMain, arguments.private);</b><br>\n649: \t\t\t\t\t}<br>\n650: \t\t\t\t}<br>\n"},{"Raw_Trace":"system.coldbox_cfc$cf.udfCall1(C:\\inetpub\\vhosts\\common\\coldbox\\system\\Coldbox.cfc:236)","codePrintPlain":"234: \t\t\t\t<!--- Run Default/Set Event not executing an event --->\n235: \t\t\t\t<cfif NOT event.isNoExecution()>\n236: \t\t\t\t\t<cfset refResults.results = cbController.runEvent(default=true)>\n237: \t\t\t\t</cfif>\n238: \n","column":0,"line":236,"template":"C:\\inetpub\\vhosts\\common\\coldbox\\system\\Coldbox.cfc","id":"??","type":"cfml","codePrintHTML":"234: \t\t\t\t&lt;!--- Run Default/Set Event not executing an event ---&gt;<br>\n235: \t\t\t\t&lt;cfif NOT event.isNoExecution()&gt;<br>\n<b>236: \t\t\t\t\t&lt;cfset refResults.results = cbController.runEvent(default=true)&gt;</b><br>\n237: \t\t\t\t&lt;/cfif&gt;<br>\n238: <br>\n"},{"Raw_Trace":"application_cfc$cf.udfCall(C:\\inetpub\\vhosts\\portal.stonbury.com-CF\\Application.cfc:75)","codePrintPlain":"73: \t\t//Process a ColdBox request only\n74: \t\tif( findNoCase('index.cfm',listLast(arguments.targetPage,\"/\")) ){\n75: \t\t\tapplication.cbBootStrap.processColdBoxRequest();\n76: \t\t}\n77: \n","column":0,"line":75,"template":"C:\\inetpub\\vhosts\\portal.stonbury.com-CF\\Application.cfc","id":"??","type":"cfml","codePrintHTML":"73: \t\t//Process a ColdBox request only<br>\n74: \t\tif( findNoCase('index.cfm',listLast(arguments.targetPage,&quot;/&quot;)) ){<br>\n<b>75: \t\t\tapplication.cbBootStrap.processColdBoxRequest();</b><br>\n76: \t\t}<br>\n77: <br>\n"}],"ErrorCode":"0","type":"org.hibernate.StaleStateException","StackTrace":"Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1\r\n\tat org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85):85\r\n\tat org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70):70\r\n\tat org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90):90\r\n\tat org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70):70\r\n\tat org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268):268\r\n\tat org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:262):262\r\n\tat org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:183):183\r\n\tat org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321):321\r\n\tat org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51):51\r\n\tat org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206):1206\r\n\tat lucee.runtime.orm.hibernate.HibernateORMTransaction.end(HibernateORMTransaction.java:63):63\r\n\tat lucee.runtime.orm.ORMConnection.setAutoCommit(ORMConnection.java:208):208\r\n\tat lucee.runtime.db.DatasourceManagerImpl.end(DatasourceManagerImpl.java:251):251\r\n\tat lucee.runtime.tag.Transaction.doFinally(Transaction.java:155):155\r\n\tat system.orm.hibernate.baseormservice_cfc$cf.udfCall6(C:\\inetpub\\vhosts\\common\\coldbox\\system\\orm\\hibernate\\BaseORMService.cfc:1485):1485\r\n\tat system.orm.hibernate.baseormservice_cfc$cf.udfCall(C:\\inetpub\\vhosts\\common\\coldbox\\system\\orm\\hibernate\\BaseORMService.cfc):-1\r\n\tat lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111\r\n\tat lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328\r\n\tat lucee.runtime.type.UDFImpl.call(UDFImpl.java:229):229\r\n\tat lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:766):766\r\n\tat lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:742):742\r\n\tat lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1589):1589\r\n\tat system.orm.hibernate.baseormservice_cfc$cf.udfCall2(C:\\inetpub\\vhosts\\common\\coldbox\\system\\orm\\hibernate\\BaseORMService.cfc:572):572\r\n\tat system.orm.hibernate.baseormservice_cfc$cf.udfCall(C:\\inetpub\\vhosts\\common\\coldbox\\system\\orm\\hibernate\\BaseORMService.cfc):-1\r\n\tat lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111\r\n\tat lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328\r\n\tat lucee.runtime.type.UDFImpl.call(UDFImpl.java:229):229\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:641):641\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:524):524\r\n\tat lucee.runtime.ComponentImpl.call(ComponentImpl.java:1760):1760\r\n\tat lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:742):742\r\n\tat lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1589):1589\r\n\tat handlers.notifications_cfc$cf.udfCall(C:\\inetpub\\vhosts\\portal.stonbury.com-CF\\handlers\\Notifications.cfc:68):68\r\n\tat lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111\r\n\tat lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328\r\n\tat lucee.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:216):216\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:642):642\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:524):524\r\n\tat lucee.runtime.ComponentImpl.callWithNamedValues(ComponentImpl.java:1773):1773\r\n\tat lucee.runtime.tag.Invoke.doComponent(Invoke.java:221):221\r\n\tat lucee.runtime.tag.Invoke.doEndTag(Invoke.java:194):194\r\n\tat system.web.controller_cfc$cf.udfCall6(C:\\inetpub\\vhosts\\common\\coldbox\\system\\web\\Controller.cfc:764):764\r\n\tat system.web.controller_cfc$cf.udfCall(C:\\inetpub\\vhosts\\common\\coldbox\\system\\web\\Controller.cfc):-1\r\n\tat lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111\r\n\tat lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328\r\n\tat lucee.runtime.type.UDFImpl.call(UDFImpl.java:229):229\r\n\tat lucee.runtime.type.scope.UndefinedImpl.call(UndefinedImpl.java:766):766\r\n\tat lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:742):742\r\n\tat lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1589):1589\r\n\tat system.web.controller_cfc$cf.udfCall5(C:\\inetpub\\vhosts\\common\\coldbox\\system\\web\\Controller.cfc:648):648\r\n\tat system.web.controller_cfc$cf.udfCall(C:\\inetpub\\vhosts\\common\\coldbox\\system\\web\\Controller.cfc):-1\r\n\tat lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111\r\n\tat lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328\r\n\tat lucee.runtime.type.UDFImpl.callWithNamedValues(UDFImpl.java:216):216\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:642):642\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:524):524\r\n\tat lucee.runtime.ComponentImpl.callWithNamedValues(ComponentImpl.java:1777):1777\r\n\tat lucee.runtime.util.VariableUtilImpl.callFunctionWithNamedValues(VariableUtilImpl.java:773):773\r\n\tat lucee.runtime.PageContextImpl.getFunctionWithNamedValues(PageContextImpl.java:1599):1599\r\n\tat system.coldbox_cfc$cf.udfCall1(C:\\inetpub\\vhosts\\common\\coldbox\\system\\Coldbox.cfc:236):236\r\n\tat system.coldbox_cfc$cf.udfCall(C:\\inetpub\\vhosts\\common\\coldbox\\system\\Coldbox.cfc):-1\r\n\tat lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111\r\n\tat lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328\r\n\tat lucee.runtime.type.UDFImpl.call(UDFImpl.java:229):229\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:641):641\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:524):524\r\n\tat lucee.runtime.ComponentImpl.call(ComponentImpl.java:1760):1760\r\n\tat lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:742):742\r\n\tat lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1589):1589\r\n\tat application_cfc$cf.udfCall(C:\\inetpub\\vhosts\\portal.stonbury.com-CF\\Application.cfc:75):75\r\n\tat lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111\r\n\tat lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328\r\n\tat lucee.runtime.type.UDFImpl.call(UDFImpl.java:229):229\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:641):641\r\n\tat lucee.runtime.ComponentImpl._call(ComponentImpl.java:524):524\r\n\tat lucee.runtime.ComponentImpl.call(ComponentImpl.java:1760):1760\r\n\tat lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:405):405\r\n\tat lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:131):131\r\n\tat lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:35):35\r\n\tat lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2257):2257\r\n\tat lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2224):2224\r\n\tat lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:456):456\r\n\tat lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:47):47\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:729):729\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291):291\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206\r\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52):52\r\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239):239\r\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206\r\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219):219\r\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106):106\r\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502):502\r\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142):142\r\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79):79\r\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88):88\r\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518):518\r\n\tat org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:844):844\r\n\tat org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668):668\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527):1527\r\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484):1484\r\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142):1142\r\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617):617\r\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61):61\r\n\tat java.lang.Thread.run(Thread.java:745):745\r\n","ExtendedInfo":""}

Thanks,

Richard

Does the problem occur when you run notification.delete() or is there an overload in NotificationService on the delete() method?

I have not seen that. Can you add orm logging and see what is the delete that is tring to execute?

Hi Luis,

I would if turning orm logging on in Lucee did anything, I get nothing on the orm.log.

Thanks,

Richard

Hi Luis,

OK I found the orm logs they were in the lucee-stdout.log in C:\lucee\tomcat\logs. Strange place to put it when there is a orm.log under every context if you ask me :slight_smile:

Anyway, I can see all the select statements but there are no calls to delete. So it doesn’t seem like the base orm service is getting that far.

Thanks,

Ricahrd

Have you tried a normal entity delete?

Does the notification have any relationships?

Yes I did and it did not delete it but also did not return an error and again no log of an sql delete. So I have no clue what is happening there.

Yes, just a simple many-to-one to the user entity.

property name="user" fieldtype="many-to-one" cfc="common.model.users.User" fkcolumn="fk_user_id";

It’s annoying as I can’t delete the notifications after I’ve processed them. I’ll see if calling delete using ormexecutequery() makes any difference.

Is it bidirectional

Luis Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com
P/F: 1-888-557-8057

Yes

property name="notifications" fieldtype="one-to-many" cfc="common.model.Notification" fkcolumn="fk_user_id" type="array" singularname="notification" inverse="true" cascade="all-delete-orphan";

Have you tried removing the “cascade” attribute (or changing it to just “delete-orphan”)?

I will try it. Thanks for the suggestion.