<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Event thrown on entity not found. in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/event-thrown-on-entity-not-found/m-p/212212#M165342</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In our system, we are hooking into the Activiti event system using a ActivitiEventHandler, detecting an ENTITY_CREATED for when a Task is created. We then pass a lightweight message containing the Task ID to a different part of our system (outside Activiti), which then will try to retrieve the full entity via either the REST API or from the TaskService (which amounts to the same thing).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The issue we're facing lies in the fact that once we have received the ENTITY_CREATED event and are trying to retrieve the Task, we get task not found exceptions.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I found this activiti forum topic &lt;/SPAN&gt;&lt;A href="https://forums.activiti.org/content/problem-using-event-handlers" rel="nofollow noopener noreferrer"&gt;https://forums.activiti.org/content/problem-using-event-handlers&lt;/A&gt;&lt;SPAN&gt; that describes the issue, that the TaskService loads from the database, and the task might not be persisted in the database at the time of the ENTITY_CREATED event.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So my questions are:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1. Am I missing something with regards to querying a task from outside of Activiti to get the 'current' versus the 'database' version of the task?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2. What was the rationale behind firing an event before it could be queried? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3. And is there any chance of changing this behaviour in the future?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;4. If none of the above is possible, how would you suggest that I proceed?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Nov 2016 06:16:36 GMT</pubDate>
    <dc:creator>mhanrahan</dc:creator>
    <dc:date>2016-11-25T06:16:36Z</dc:date>
    <item>
      <title>Event thrown on entity not found.</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/event-thrown-on-entity-not-found/m-p/212212#M165342</link>
      <description>Hi,In our system, we are hooking into the Activiti event system using a ActivitiEventHandler, detecting an ENTITY_CREATED for when a Task is created. We then pass a lightweight message containing the Task ID to a different part of our system (outside Activiti), which then will try to retrieve the fu</description>
      <pubDate>Fri, 25 Nov 2016 06:16:36 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/event-thrown-on-entity-not-found/m-p/212212#M165342</guid>
      <dc:creator>mhanrahan</dc:creator>
      <dc:date>2016-11-25T06:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Event thrown on entity not found.</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/event-thrown-on-entity-not-found/m-p/212213#M165343</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Michael,&lt;/P&gt;&lt;P&gt;I think Frederik gave you a pretty good technical answer in the forum post you referenced.&lt;BR /&gt;It's really a matter of timing. The event is thrown inside the Entity persistence class, so it really depends on the performance of the database and the transaction boundaries as to how long it is before the database record is actually available.&lt;BR /&gt;Take the TaskEntity as an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE style="color: #000000; background-color: #ffffff; font-size: 9.0pt;"&gt;&lt;TABLE class="j-table jiveBorder" style="border: 1px solid #c6c6c6;" width="100%"&gt;&lt;THEAD&gt;&lt;TR style="background-color: #efefef;"&gt;&lt;TH&gt;TaskEntity.java&lt;/TH&gt;&lt;/TR&gt;&lt;/THEAD&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;PRE style="background-color: #ffffff; font-size: 9.0pt;"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;...&lt;BR /&gt;...&lt;BR /&gt;public void &lt;/SPAN&gt;insert(ExecutionEntity execution) {&lt;BR /&gt;&amp;nbsp; CommandContext commandContext = Context.&lt;SPAN&gt;getCommandContext&lt;/SPAN&gt;();&lt;BR /&gt;&amp;nbsp; DbSqlSession dbSqlSession = commandContext.getDbSqlSession();&lt;BR /&gt;&amp;nbsp; dbSqlSession.insert(&lt;SPAN style="color: #000080; font-weight: bold;"&gt;this&lt;/SPAN&gt;);&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; &lt;SPAN style="color: #808080;"&gt;// Inherit tenant id (if applicable)&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(execution != &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null &lt;/SPAN&gt;&amp;amp;&amp;amp; execution.getTenantId() != &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; setTenantId(execution.getTenantId());&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if&lt;/SPAN&gt;(execution != &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; execution.addTask(&lt;SPAN style="color: #000080; font-weight: bold;"&gt;this&lt;/SPAN&gt;);&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; commandContext.getHistoryManager().recordTaskCreated(&lt;SPAN style="color: #000080; font-weight: bold;"&gt;this&lt;/SPAN&gt;, execution);&lt;BR /&gt;&amp;nbsp; &lt;BR /&gt;&amp;nbsp; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if&lt;/SPAN&gt;(commandContext.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp; commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ActivitiEventBuilder.&lt;SPAN&gt;createEntityEvent&lt;/SPAN&gt;(ActivitiEventType.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;ENTITY_CREATED&lt;/SPAN&gt;, &lt;SPAN style="color: #000080; font-weight: bold;"&gt;this&lt;/SPAN&gt;));&lt;BR /&gt;&amp;nbsp;&amp;nbsp; commandContext.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ActivitiEventBuilder.&lt;SPAN&gt;createEntityEvent&lt;/SPAN&gt;(ActivitiEventType.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;ENTITY_INITIALIZED&lt;/SPAN&gt;, &lt;SPAN style="color: #000080; font-weight: bold;"&gt;this&lt;/SPAN&gt;));&lt;BR /&gt;&amp;nbsp; }&lt;BR /&gt;}&lt;BR /&gt;...&lt;BR /&gt;...&lt;/PRE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/PRE&gt;&lt;P&gt;This is typical of the event emitter pattern throughout the engine.&lt;BR /&gt;Now, most of the time, the event data will be persisted externally, but from your description, you are simply storing the task ID and relying on a lookup you get the rest of the data.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;For most reporting style operations this shouldnt be a problem because the database transaction will be committed, however if you are making an immediate callback (if so, why not just take the data from the event body?) then you run the risk of a race condition.&lt;BR /&gt;&lt;BR /&gt;Now to your specific questions.&lt;BR /&gt;&lt;BR /&gt;1. The engine is stateless, meaning the state is only stored in the database. All REST calls will access the persistence layer.&lt;/P&gt;&lt;P&gt;2. Rationale - can't speak to that, but by including the content of the entity (in this case a task) in the event body, it would seem un-necessary to tightly couple the event to the DB persistence.&lt;/P&gt;&lt;P&gt;3. The beauty of open source is that everyone gets to have their say. If you want the behavior changed, open a jira and state your case. Better still, create your own implementation and open a pull request. This doesnt guarantee anything, but it gets a discussion started.&lt;/P&gt;&lt;P&gt;4. How to proceed, depends on the scenario. First off, don't assume the event and persistence are tightly coupled. As you have seen, they are not. If you need the task information immediately, then take it from the event body. One thing is for sure, the record will make it into the database, you you can add retry logic if you want (not a good idea if response time is critical).&lt;BR /&gt;&lt;BR /&gt;Perhaps you can describe the interaction and timing so we may offer other options.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Greg&lt;/P&gt;&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/tag/bp3/tg-p"&gt;&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 16 Dec 2016 20:28:03 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/event-thrown-on-entity-not-found/m-p/212213#M165343</guid>
      <dc:creator>gdharley</dc:creator>
      <dc:date>2016-12-16T20:28:03Z</dc:date>
    </item>
  </channel>
</rss>

