Manjeet Mahto
Manjeet Mahto

Reputation: 79

ORM issue after upgrading to ColdFusion 2018 from version 11

We migrated from ColdFusion 11 to ColdFusion 2018 and now ORM is breaking the EntitySave method and we are getting below error message.

Error Message - The root cause of this exception was: coldfusion.orm.hibernate.HibernateSessionException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1.

We have 2 classes with one-to-many relationship like Email.cfc (parent) and EmailItems.cfc (child). When we try to save Email.cfc object the hibernate creates an UPDATE query for EmailItems as well and this is happening with ColdFusion 2018 only.

Here is the defined property in Email.cfc.

<cfproperty name="EmailItems" 
            lazy="true" 
            fieldtype="one-to-many" 
            inverse="true" 
            fkcolumn="EmailID" 
            cfc="EmailItem" 
            singularName="EmailItem" 
            type="struct" 
            structkeycolumn="EmailItemKey" 
            structkeytype="string" 
            cascade="none"
/>

We are using inverse and it still create an UPDATE query for child class 'EmailItems' which is the reason for failing EntitySave(Email). Everything works fine with ColdFusion 11.

Upvotes: 2

Views: 370

Answers (1)

Manjeet Mahto
Manjeet Mahto

Reputation: 79

Finally, I found the fix for this. It seems the inverse="true" properties doesn't work the same WITH cf2018 as it is working with CF2011.

After doing some research found that, by default a cascade property is added in <cfproperty> tag for one-to-many relationship whose value is UPDATE that means for any orphaned child object it is trying to update while this object doesn't exist at database level.

So, when adding cascade="save-update" in my <cfproperty> tag for on-to-many relationship, it fixes the problem because now it tries to INSERT instead of UPDATE for any orphaned child object.

Upvotes: 2

Related Questions