Atomic database commit of related entities

0
Hi all,   I have a one-to-many association between two entities in my data model. I would like to be able to commit both the associated objects and main object all at once, and having problems doing this.   To give an example, here is my domain model: In the main screen all books are displayed in a data grid 2, as follows:     When I want to edit a book, I use an overview page that also shows the copies, in a nested data grid. Here is how it looks like:     My problem is: when I delete one of the copies or add a new copy, but then press cancel on this page, I still have an updated copies entity committed to the database. I would like to have a temporary version of the associated entity (in this case copies of the books), and would like to have it committed to the database ONLY WHEN the user clicks on Save button. Hence any updates on the copies will be temporary until then, and will not be committed in case user clicks on Cancel.   Does anyone have an opinion on how I can have such a solution?  
asked
2 answers
0

The auto number thing is not so easy to change I think - it is a database driven number; not sure you want to go about and mess with those numbers. :) 

 

Yes it takes quite a few flows alas, but then again you have full access control and validate what is written away via the server in specific contexts. This is probably the safest way :) 

 

if you want to purge half-completed changes, just associate to $currentSession with a cascading delete. When the session is killed, the temp copy is also killed :) 

 

if my solution worked, can you mark this as correct? Ty! 

answered
0

Hello Alparslan Arslan,

 

As already suggested by Wouter Penris, there are quite some options in which we can handle this use case. Below is one of the solution which we have implemented.

 

We have taken a enumeration in the Copy Entity with values as "New, Modified and Deleted".

1. When we create a new object of the entity "Copy", we set the enumeration to "New" and on hit of the save button on the Book_NewEdit page, we retrieve all the "Copy" with value as "New" and commit them and when user presses cancel, we retrieve all the "Copy" with value as "New" and delete them.

2. When we update any existing object of the entity "Copy", we set the enumeration to "Modified" and on hit of the save button on the Book_NewEdit page, we retrieve all the "Copy" with value as "Modified" and commit them and when user presses cancel, we retrieve all the "Copy" with value as "Modified" and rollback them to get the older values.

3. When we delete any existing object of the entity "Copy", we set the enumeration to "Deleted" and on hit of the save button on the Book_NewEdit page, we retrieve all the "Copy" with value as "Deleted" and delete them and when user presses cancel, we retrieve all the "Copy" with value as "Deleted" and rollback them to get the older values.

 

Hope this helps!

 

Regards

Praharaj

answered