Skip to Content
author's profile photo Former Member
Former Member

On prepare validator and error with saving model.

Hello,

I want to use on prepare validator to save changes to the model in "audit object" and I have one question. On prepare validator is called before saving the model it is possible that I save old/new values to "audit object" but in reality the model wouldn't be saved to the DB (for instance there will be problems with validation or there will be problem with connections to DB). Is there any solution to this problem ? How to save date to "audit object" using interceptor "before saving" but be sure that date was really saved ? I cannot use Hybris auditing mechanism because changes are not made by hmc but by custom cockpit.

Thanks in advance.

Adam

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Sep 05, 2016 at 10:11 AM

    Hi,

    here you can read about transactions and how to deal with them in hybris. You may also use code like in the sample to extract data about model changes:

     final ItemModelContext itemModelContext = ModelContextUtils.getItemModelContext(itemModel);
       if (itemModelContext != null)
       {
         ModelValueHistory mvh = ((ItemModelContextImpl) itemModelContext).getValueHistory();
         //Some logic here to aggregate the history
         //Probably for storin it 
       }
       
      modelService.saveAll(/*model & hisroty data*/)
    
    

    Cheers, Wojtek

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.