{"id":20069,"date":"2021-01-18T13:00:32","date_gmt":"2021-01-18T12:00:32","guid":{"rendered":"https:\/\/blog.trifork.com\/?p=20069"},"modified":"2021-01-18T13:00:32","modified_gmt":"2021-01-18T12:00:32","slug":"axon-framework-error-message","status":"publish","type":"post","link":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/","title":{"rendered":"On the \u201cAggregate identifier must be non-null after applying an event\u201d error message"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"977\" height=\"648\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png\" alt=\"\" class=\"wp-image-20081\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png 977w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1-300x199.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1-768x509.png 768w\" sizes=\"auto, (max-width: 977px) 100vw, 977px\" \/><figcaption>Photo by Digital Design Journal on Pinterest <\/figcaption><\/figure>\n\n\n\n<p>Even when you have been developing applications using the Axon framework for years, you still come across learnings that are worthwhile sharing. Today I learned such a lesson and I would like to share it with you. <br \/><\/p>\n\n\n\n<p>I was adding a new property to an Entity in my application and updated the Revision of the Create and Update events. After, I wrote an Upcaster and ran a Reset to replay all my events and did the actual update of the Entity in the View Models. This is Axon business as usual. Next, I inspected my View Model database and was happy to see the new property present with the default value I gave it in the Upcaster. Cool: Done! Uhhhh. No. <br \/><\/p>\n\n\n\n<p>When I tested updating the value of the new property through the GUI, it failed. Excuse me? It\u2019s a simple new Boolean value. I looked at the network traffic between the browser and the backend and saw the GUI communicating the new property correctly. I also put a breakpoint in my REST Controller in the backend. All OK. However, then I spotted a stacktrace and received this message: <br \/><\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p style=\"text-align:center\"><strong>org.axonframework.eventsourcing.IncompatibleAggregateException:\nAggregate identifier must be non-null after applying an event. Make sure the\naggregate identifier is initialized at the latest when handling the creation event.<\/strong><\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Initially, I couldn\u2019t understand what was going on. I have been adapting an Entity in my application for ages, therefore I was absolutely convinced I handled it\u2019s Aggregate IDs properly. There was something else wrong, but what? What I discovered was logical in a way, but still unexpected: the root cause of the problem was the switching of the git branches. This is what really happened:<\/p>\n\n\n\n<p>The day before I had made another change on the same Aggregate, but I was working on <em>another git branch<\/em>. That change did not per se require an Upcaster to make my application run well. I added a sub-property in the following way:<\/p>\n\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>AGGREGATE<\/strong> <br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - property 1<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - property 2<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - sub property 2.a<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - sub property 2.b<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - sub property 2.c&nbsp;&nbsp; &lt;\u2014 added yesterday<br \/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - property 3  <br \/><br \/><\/pre>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>As this branch was under review, I switched back to \u2018master\u2019 and made another branch today:<\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>AGGREGATE<\/strong><br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - property 1  <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - property 2  <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - sub property 2.a  <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - sub property 2.b  <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - property 3  <br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; - property 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\u2014 added today   <br \/><\/pre>\n\n\n\n<div style=\"height:15px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Note that this<strong> did NOT <\/strong>contain the sub property 2.c yet. And it <strong>should not, <\/strong>as this was under review. But now I found myself in trouble because I needed to test the changes I was experimenting with yesterday. As a result, there were Update events in my event store since yesterday containing the sub property 2.c. <br \/><\/p>\n\n\n\n<p>All updates on these Aggregates were failing for a perfectly logical reason: when Axon was applying today\u2019s update event, it loaded the Aggregate\u2019s state. To do so it loaded all events with the same Aggregate ID, found an Update event containing sub property 2.c, and failed. It gave an&nbsp; \u201cIncompatibleAggregateException\u201d message. In most cases, such an Exception is caused by improperly setting the Aggregate ID, but not in my case. <br \/><\/p>\n\n\n\n<p>To solve the problem you may, of course, consider merging yesterday\u2019s branch into the one of today, but that makes the branches dependent. As an alternative, you can delete events today, but that makes the branches dependent. As an alternative, you can delete events containing the sub property 2.c from the event store. This solution is more viable because you can\u2019t delete events when using the Axon Server and because it forbids you to get a recent backup and restore it. <br \/><\/p>\n\n\n\n<div style=\"height:10px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Conclusion<\/strong><br \/>When you see the Axon error message \u201c<strong>org.axonframework.eventsourcing.IncompatibleAggregateException: Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event.<\/strong>\u201d&nbsp; think of ID initialisation as a first solution. Then also remember you may have incompatible events in your event store due to branch switching in development.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/bit.ly\/3BAo305\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"256\" src=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png\" alt=\"\" class=\"wp-image-20303\" srcset=\"https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1024x256.png 1024w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-300x75.png 300w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-768x192.png 768w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1536x384.png 1536w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-2048x512.png 2048w, https:\/\/trifork.nl\/blog\/wp-content\/uploads\/sites\/3\/2022\/02\/Blog-Banner-1-1920x480.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Even when you have been developing applications using the Axon framework for years, you still come across learnings that are worthwhile sharing. Today I learned such a lesson and I would like to share it with you. I was adding a new property to an Entity in my application and updated the Revision of the [&hellip;]<\/p>\n","protected":false},"author":121,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[81,10],"tags":[80],"class_list":["post-20069","post","type-post","status-publish","format-standard","hentry","category-axon-framework","category-development","tag-axon-framework"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>On the \u201cAggregate identifier must be non-null after applying an event\u201d error message - Trifork Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"On the \u201cAggregate identifier must be non-null after applying an event\u201d error message - Trifork Blog\" \/>\n<meta property=\"og:description\" content=\"Even when you have been developing applications using the Axon framework for years, you still come across learnings that are worthwhile sharing. Today I learned such a lesson and I would like to share it with you. I was adding a new property to an Entity in my application and updated the Revision of the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/\" \/>\n<meta property=\"og:site_name\" content=\"Trifork Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-18T12:00:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png\" \/>\n<meta name=\"author\" content=\"Wilco Koorn\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Wilco Koorn\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/\",\"url\":\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/\",\"name\":\"On the \u201cAggregate identifier must be non-null after applying an event\u201d error message - Trifork Blog\",\"isPartOf\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png\",\"datePublished\":\"2021-01-18T12:00:32+00:00\",\"author\":{\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/66efcb420662bc45e623c0f9368b91df\"},\"breadcrumb\":{\"@id\":\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#primaryimage\",\"url\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png\",\"contentUrl\":\"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/trifork.nl\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"On the \u201cAggregate identifier must be non-null after applying an event\u201d error message\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/trifork.nl\/blog\/#website\",\"url\":\"https:\/\/trifork.nl\/blog\/\",\"name\":\"Trifork Blog\",\"description\":\"Keep updated on the technical solutions Trifork is working on!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/trifork.nl\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/66efcb420662bc45e623c0f9368b91df\",\"name\":\"Wilco Koorn\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a61a60b2bf91009cbb3f74505ec8e43b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a61a60b2bf91009cbb3f74505ec8e43b?s=96&d=mm&r=g\",\"caption\":\"Wilco Koorn\"},\"url\":\"https:\/\/trifork.nl\/blog\/author\/wilcok\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"On the \u201cAggregate identifier must be non-null after applying an event\u201d error message - Trifork Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/","og_locale":"en_US","og_type":"article","og_title":"On the \u201cAggregate identifier must be non-null after applying an event\u201d error message - Trifork Blog","og_description":"Even when you have been developing applications using the Axon framework for years, you still come across learnings that are worthwhile sharing. Today I learned such a lesson and I would like to share it with you. I was adding a new property to an Entity in my application and updated the Revision of the [&hellip;]","og_url":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/","og_site_name":"Trifork Blog","article_published_time":"2021-01-18T12:00:32+00:00","og_image":[{"url":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png","type":"","width":"","height":""}],"author":"Wilco Koorn","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Wilco Koorn","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/","url":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/","name":"On the \u201cAggregate identifier must be non-null after applying an event\u201d error message - Trifork Blog","isPartOf":{"@id":"https:\/\/trifork.nl\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#primaryimage"},"image":{"@id":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#primaryimage"},"thumbnailUrl":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png","datePublished":"2021-01-18T12:00:32+00:00","author":{"@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/66efcb420662bc45e623c0f9368b91df"},"breadcrumb":{"@id":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/trifork.nl\/blog\/axon-framework-error-message\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#primaryimage","url":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png","contentUrl":"https:\/\/trifork.nl\/articles\/wp-content\/uploads\/sites\/3\/2021\/01\/Blogpost_picture-1.png"},{"@type":"BreadcrumbList","@id":"https:\/\/trifork.nl\/blog\/axon-framework-error-message\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/trifork.nl\/blog\/"},{"@type":"ListItem","position":2,"name":"On the \u201cAggregate identifier must be non-null after applying an event\u201d error message"}]},{"@type":"WebSite","@id":"https:\/\/trifork.nl\/blog\/#website","url":"https:\/\/trifork.nl\/blog\/","name":"Trifork Blog","description":"Keep updated on the technical solutions Trifork is working on!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/trifork.nl\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/66efcb420662bc45e623c0f9368b91df","name":"Wilco Koorn","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/trifork.nl\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a61a60b2bf91009cbb3f74505ec8e43b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a61a60b2bf91009cbb3f74505ec8e43b?s=96&d=mm&r=g","caption":"Wilco Koorn"},"url":"https:\/\/trifork.nl\/blog\/author\/wilcok\/"}]}},"_links":{"self":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/20069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/users\/121"}],"replies":[{"embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/comments?post=20069"}],"version-history":[{"count":0,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/posts\/20069\/revisions"}],"wp:attachment":[{"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/media?parent=20069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/categories?post=20069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trifork.nl\/blog\/wp-json\/wp\/v2\/tags?post=20069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}