reset password
Author Message
ashoush
Posts: 25
Posted 22:43 Nov 17, 2009 |

Hi Dr. Sun,

 

When a student tries to edit a previously solved assignment, I delete the list of previous answers from onlinesubmission class and add the newly updated answers to it as new answer objects (so they will have new ID in database). If someone doesn't upload a new file for a question that had a file previously, I want to keep that file. If I associate that old file object with the new answer object, I get an error while saveing the submission to database. Because hibernate wants to delete that file because it's answer is being deleted. I tried couple of different things to save the file but each of them generates a new database related error. What do you think is the right way of doing this?

 

Thanks,

Arash

cysun
Posts: 2935
Posted 23:04 Nov 17, 2009 |

I don't see why you want to delete the old answers instead of updating them.

If you really want to delete the answers but keep the file, try cascade="save-update" so deleting the answer does not delete the file, i.e.

<many-to-one name="uploadedFile" class="File" column="uploaded_file_id" unique="true" cascade="save-update" />

ashoush
Posts: 25
Posted 23:25 Nov 17, 2009 |

Thanks that solved the problem.

The reason I am doing it this way it that I am not using the simple form controller so I am developing my own edit/update controller in which it's easier to share same code for edit and add.

Another question that I have: is there a way to use simple form controller for mroe complex forms which modify more than one kind of object?

cysun
Posts: 2935
Posted 07:25 Nov 18, 2009 |

Another question that I have: is there a way to use simple form controller for mroe complex forms which modify more than one kind of object?

The short answer is no, you can only have one backing object. However, you can always use a backing object that contains other objects. For example, if you want to modify object a and object b, you can create an object c of the type:

class C {

A a;

B b;

}