How to rollback database in controller?

Topics: Writing modules
Apr 8, 2013 at 2:18 AM
Hi all,

In my controller, I want to create some objects. But when it throws an exception, i want to rollback all objects which have inserted to database.

Please give a way to resolve it.

Thanks,
Coordinator
Apr 8, 2013 at 3:14 AM
It should be automatic: exceptions should cause the transaction to roll back.
Apr 8, 2013 at 3:21 AM
I have seen that. But it's only automatic when it throw an exception about database.
How it works with another exceptions?
Coordinator
Apr 8, 2013 at 3:29 AM
Catch the exception, rollback and re-throw.
Apr 8, 2013 at 3:30 AM
BertrandLeRoy wrote:
Catch the exception, rollback and re-throw.
How could i do that by manually?
Apr 8, 2013 at 3:32 AM
My meaning is with another exception, then it doesn't rollback database automatic?
Coordinator
Apr 8, 2013 at 3:38 AM
I don't know what you mean by "manually" in this context.
Apr 8, 2013 at 3:41 AM
BertrandLeRoy wrote:
I don't know what you mean by "manually" in this context.
It's meaning I could rollback database by code in my controller
Coordinator
Apr 8, 2013 at 7:40 AM
Inject an ISessionLocator. From that, you can get the nHibernate, then the transaction.