tracker issue : CF-4024153

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

ormClearSession and ormCloseSession causes entityRelations not to be persisted

| View in Tracker

Status/Resolution/Reason: Closed/Withdrawn/NotABug

Reporter/Name(from Bugbase): Jork Zijlstra / Jork Zijlstra (Jork Zijlstra)

Created: 07/22/2015

Components: ORM Support

Versions: 10.0

Failure Type: Data Loss

Found In Build/Fixed In Build: Final /

Priority/Frequency: Critical / All users will encounter

Locale/System: English / Linux Ubuntu 10.10

Vote Count: 0

Problem Description:
Calling ormClearSession or ormClosession after an entitysave nog all cascading data is saved. When you have on object with an one-to-many property both object are persisted, but not the relation between them.

Steps to Reproduce:
In the zip file I have added the code.

It have an object Test with a one-to-many relation to TestItem

1) Create tables with sql
2) run index.cfm
- it creates an Test object
- it adds an TestItem to Test
- it entitySaves Test
- it calles ormClearSession 

3) look at the dumps
Test doens't have an testItem

Actual Result:
In the database a Test and TestItem records is saved. Only in the TestItem table the testID column remains null.
So when entityLoading the Test again it doens't have an testItem.

Expected Result:
When enityLoading the Test again it doens have an testItem.

Any Workarounds:
Put a transaction {} around the entitySave

ormFlush after entitySave doens't help.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	4024153

External Customer Info:
External Company:  
External Customer Name: Jork
External Customer Email:  
External Test Config: My Hardware and Environment details:

Ubuntu 12.04, CF10,0,15,292620

Attachments:

  1. July 22, 2015 00:00:00: 1_ormflush_1.zip
  2. July 24, 2015 00:00:00: 2_missing-relation.png
  3. July 24, 2015 00:00:00: 3_test1.png

Comments:

Hi Jork, OrmFlush works fine at my end. I have tested it with ColdFusion 10 Update 16 and JDK 1.8.0_20 If I remove ormflush, then I am observing this issue which seems to be a desired behavior. Please provide settings summary of ColdFusion server.
Comment by Nimit S.
6527 | July 23, 2015 11:31:36 PM GMT
I have just updated my system to CF Version 10,0,16,293499. I have also tested it on our test environment. When using the ormFlush it seems to work. However still when forgetting the ormflush() it still saves the entities but not the relatation between them. See attachments.
Comment by External U.
6528 | July 24, 2015 03:21:32 AM GMT
Hi Jork, ColdFusion flushes ORM session at request end by default. You have to call ormFlush to persist data before closing/clearing ORM session, if you are calling ormCloseSession/ormCkearSession function explicitly. Is there any specific reason to close the session explicitly? Are you using cftransaction to maintain session manually?
Comment by Nimit S.
6529 | August 19, 2015 03:38:51 AM GMT
Hi Jork, Please provide me an update on this issue.
Comment by Nimit S.
6530 | September 13, 2015 12:25:34 PM GMT
Hi Jork, We are still waiting for your response. Please provide us an update on this issue.
Comment by Nimit S.
6531 | September 21, 2015 11:36:16 PM GMT
We are using a bidirectional relations, so a parent knows its childs and a child knows it parent For example: component name="Test" property name="testItem" cfc="TestItem" fieldtype="one-to-one" cascade="delete" mappedby="test" inverse="true" and the other side: component name="Testitem" property name="test" cfc="Test" fieldtype="one-to-one" cascade="save-update"; So you create and Test and add a TestItem to it. Calling a entitySave doesn't mean that the relation is persisted instantly, like you said some part it persisted at request end. Directly after calling entitySave TestItem doens't have a Test. When bulk inserting data you can clearly see what is happening. After calling entitySave (without ornflush) a Test and TestItem record is persisted to the database. Only at the end of the request the updates are persisted which updates the record to contain the relation between Test and TestItem. So these are seperate updates on the database. So the only way to have access to this birectional data within the same request is to close or clear the ormSession explicitly, so that these updates a fired. Only when you are not using ormflush the updates aren't fired. So the database contains a Test and TestItem record but they have no relation between them. So some data is lost.
Comment by External U.
6532 | September 22, 2015 02:31:09 AM GMT
I am a little confused about the expectation here. If the session is cleared explicitly before it gets flushed to the database, there will be data loss and this is expected. Let me know if i am missing something here. Closing this for now but will re-open if there is a different expectation.
Comment by Nimit S.
6533 | September 29, 2015 05:02:22 AM GMT
"There will be data loss and this is expected." Well I was expecting no saved data or all saved data and not partly saved data. Thanks for clearing this up that it is expected behavior.
Comment by External U.
6534 | September 29, 2015 05:15:24 AM GMT