cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

how to perform save before exception throw

Former Member
0 Likes
1,488

Hi team,

I am going to throw exception , but before it I want to save some data to db. for now the rollback is triggered. Is there some way to save data before exception throw and avoid rollback of this save?

thank you, Vitaliy

Accepted Solutions (0)

Answers (3)

Answers (3)

arvind-kumar_avinash
Active Contributor
0 Likes

Hi - if I understood your requirement correctly, you want the data to be saved irrespective of an exception is thrown. To deal with such a requirement, I would stick to Java basics and would use finally{} block.

 finally {
     //put your data saving code here
 }
arvind-kumar_avinash
Active Contributor
0 Likes

Hi - did it help?

sduvvuri
Explorer
0 Likes

Hi ,

You can use transaction commit() before the exception is thrown so that the data is saved.

Reference : https://help.hybris.com/1811/hcd/8c7387f186691014922080f2e053216a.html

Hope this helps.

Thanks, .

Former Member
0 Likes

thank you... will take a look

Former Member
0 Likes

Hi , We can throw the exception by interceptor .Write validate interceptor and onValidate write u r logic which you want check if fails throw exception or else save the data data it wont rollback

Former Member
0 Likes

there is no problem in throwing exception.. there is problem that I need to save state of object before I throw exception. And the exception should be thrown in any case