title: Axon FrameWork: How to rollback in the domain_event_entry table
body: <p>You can see my sample classes below. </p>
  
  <p>Basically, I want to use Axon's <code>domain_event_entry</code> table to store the events, and my own entity table to store the entities. 
  I know that If I fire a <code>CreateTemplateCommand</code> which is handled in the Aggregate an Event will be published, and that after that it will go to the <code>@EventSourcingHandler</code> where Axon will persist the event in his <code>domain_event_entry</code> table. </p>
  
  <p>After this part, it will go to my external <code>@EventHandler</code> where I want to persist my entity from the event. 
  As you can see, I throw a <code>RunTimeException</code>, because I want to simulate a rollback. It will rollback in my own table, but in the Axon's <code>domain_event_entry</code> table there will be the event. 
  So I will get my entity table empty, and my Axon's table with the <code>TemplateCreatedEvent</code> in it, but I want to rollback the <code>domain_event_entry</code> too. </p>
  
  <p>How can I rollback the <code>domain_event_entry</code> table or should I use compensating events for that?</p>
  
  <pre><code>@Aggregate
  @Getter
  @Setter
  @NoArgsConstructor
  public class TemplateAggregate {
  
    private static final transient Logger logger = LoggerFactory.getLogger(TemplateAggregate.class);
    @AggregateIdentifier
    private String templateId;
  
     private LocalDate createdAt;
  
     private String createdBy;
  
     private String description;
  
     private LocalDate modifiedAt;
  
     private String modifiedBy;
  
     private String name;
  
     private LocalDate validFrom;
  
     private LocalDate validTo;
  
     private File file;
  
     private String fileName;
  
     private long fileSize;
  
     private LocalDate fileDate;
  
     private String fileUploader;
  
    @CommandHandler
    public TemplateAggregate(CreateTemplateCommand cmd) {
      AggregateLifecycle.apply(new TemplateCreatedEvent(cmd));
    }
  
    @CommandHandler
    public void handle(ModifyTemplateCommand cmd) {
      AggregateLifecycle.apply(new TemplateModifiedEvent(cmd));
    }
  
    @EventSourcingHandler
    public void on(TemplateCreatedEvent event) {
      this.templateId = event.getTemplateId();
       this.createdAt = event.getCreatedAt();
       this.createdBy = event.getCreatedBy();
       this.description = event.getDescription();
       this.name = event.getName();
       this.validFrom = event.getValidFrom();
       this.validTo = event.getValidTo();
       this.file = event.getFile();
       this.fileName = event.getFileName();
       this.fileSize = event.getFileSize();
       this.fileDate = event.getFileDate();
       this.fileUploader = event.getFileUploader();
      logger.info("TemplateAggregate - TemplateCreatedEvent");
    }
  
    @EventSourcingHandler
    public void on(TemplateModifiedEvent event) {
      this.templateId = event.getTemplateId();
       this.createdAt = event.getCreatedAt();
       this.createdBy = event.getCreatedBy();
       this.description = event.getDescription();
       this.name = event.getName();
       this.validFrom = event.getValidFrom();
       this.validTo = event.getValidTo();
       this.file = event.getFile();
       this.fileName = event.getFileName();
       this.fileSize = event.getFileSize();
       this.fileDate = event.getFileDate();
       this.fileUploader = event.getFileUploader();
       this.modifiedAt = event.getModifiedAt();
       this.modifiedBy = event.getModifiedBy();
      logger.info("TemplateAggregate - TemplateModifiedEvent");
    }
  
  }
  </code></pre>
  
  <p>My External @EventHandler class:</p>
  
  <pre><code>@Service
  public class TemplateCreatedEventHandler {
  
    private static final transient Logger logger =
        LoggerFactory.getLogger(TemplateCreatedEventHandler.class);
  
    @Autowired
    private TemplateRepository templateRepository;
  
    @Transactional
    @EventHandler
    public void on(TemplateCreatedEvent event) {
      templateRepository.save(new TemplateQueryEntity(event));
      logger.info("EventHandler - TemplateCreatedEvent");
      throw new RuntimeException();
    }
  
  
  
  }
  </code></pre>