tracker issue : CF-4204539

select a category, or use search below
(searches all categories and all time range)
Title:

regression: javax.persistence.TransactionRequiredException when doing native createQuery() calls

| View in Tracker

Status/Resolution/Reason: To Test//Fixed

Reporter/Name(from Bugbase): Luis M. / ()

Created: 06/18/2019

Components: ORM Support

Versions: 2018

Failure Type:

Found In Build/Fixed In Build: all /

Priority/Frequency: Normal /

Locale/System: / Win All

Vote Count: 0

Problem Description:

If you do a native query call in acf2016 and acf11 this worked without creating native transactions.  In 2018, you get an exception.

Steps to Reproduce:

{code:java}
transaction{
// delete using lowercase id convention from hibernate for identifier
var datasource = variables.orm.getEntityDatasource( arguments.entityName );
var query = variables.orm.getSession( datasource )
	.createQuery( "delete FROM #arguments.entityName# where id in (:idlist)" );
query.setParameterList( "idlist", arguments.id );
count = query.executeUpdate();
}
{code}


Actual Result:

javax.persistence.TransactionRequiredException: Executing an update/delete query at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1496) at sun.reflect.GeneratedMethodAccessor172.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at coldfusion.runtime.StructBean.invoke(StructBean.java:507) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3476) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3357) at cfBaseORMService2ecfc962975903$func_CF_ANONYMOUSCLOSURE_221.runFunction(/Users/lmajano/Sites/cboxdev/coldbox-core-modules/cborm/models/BaseORMService.cfc:939) at coldfusion.runtime.Closure.invoke(Closure.java:111) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:447) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:398) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:371) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:597) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3310) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:3277) at cfBaseORMService2ecfc962975903$func$TRANSACTIONED.runFunction(/Users/lmajano/Sites/cboxdev/coldbox-core-modules/cborm/models/BaseORMService.cfc:1883) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:553) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:484) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:447) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:95) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:398) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:371) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:287) at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:3928) at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:3908) at cfBaseORMService2ecfc962975903$funcDELETEBYID.runFunction(/Users/lmajano/Sites/cboxdev/coldbox-core-modules/cborm/models/BaseORMService.cfc:953) Executing an update/delete query



Expected Result:

The count of deleted objects.

Any Workarounds:

You have to add a hibernate transaction.  Before in previous ACF versions, the CF transaction was enough for this query to cover it.  Now it breaks

Attachments:

Comments:

@Luis M: This is a problem with hibernate source-code, As you can see in the comments of this issue https://hibernate.atlassian.net/browse/HHH-13262 , this bug was introduced in hibernate version 5.1 and got fixed in version 5.4, ACF ships with version 5.2 with some customizations, for the upgrade instruction, hibernate folks have given the following workaround of setting the property *_hibernate.allow_update_outside_transaction=true_* , which doesn't seems to have worked, I have tried backporting those changes to version 5.2 and built a custom jar which is under testing phase, once the testing gets completed we can share the jar with you which should ideally fix this.
Comment by Ashudeep S.
30940 | June 19, 2019 11:46:17 AM GMT
Thanks for this incredibly fast comment! I really really appreciate that @ashudeep! I have been able to bypass it by using native hibernate transactions, which I will leave with a comment unti lthis is fixed and then I will remove it. However, I am so glad you know what to do!
Comment by Luis M.
30941 | June 19, 2019 03:36:39 PM GMT
@Luis M: It seems like you are directly calling the hibernates API rather than using our versions of methods. I have attached the hibernate-core-5.2.19-SNAPSHOT.jar with this JIRA, which contains the fix from hibernate side. Can you please download it and run it across your test-cases to verify that it works fine with your framework?
Comment by Ashudeep S.
30967 | June 28, 2019 07:48:32 AM GMT