2

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.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • 1
    Two things come to mind. 1. Does it work without the foreign key 2. I wonder if Hibernate has cache that needs to be flushed. – James A Mohler Jan 02 '19 at 16:54
  • Thanks for responding. It's not due to hibernate cache because my call is within CFTRANSACTION tag. Below is the code - transaction { arguments.email.setIsPersisted(true); EntitySave(arguments.email); } – Manjeet Mahto Jan 02 '19 at 20:01

1 Answers1

2

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.

James A Mohler
  • 11,060
  • 15
  • 46
  • 72