Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
READ_UNCOMMITTED Transaction not working?
Hey Guys,
I'm totally stuck on this one so I am hoping one of the community AllStars can help me out here. My scenario is this. I have a portlet on a page. When the users leaves the page, the "unload" event that the browser fires causes a Resource call for my portlet. My Resource Command class is hit at which point I either update or add a record using my XXXLocalService sb class. The user then navigates to the other page. If they navigate to a page with a separate portlet that also uses the XXXLocalService sb class, they're not seeing the last add/update that was just made. I can see the row in the table but I am guessing that it is not yet committed. The default isolation is READ_COMMITTED so it makes sense that the update is not seen. To prove this theory I activated a property in the portal-ext
<pre>
jdbc.default.defaultTransactionIsolation=READ_UNCOMMITTED
</pre>
When I set this and restart my portal, then I have no issues -- except for the fact that all transactions are not in a "dirty mode" and that it could create strange behaviour under load -- I'm fine with a READ_UNCOMMITTED transaction, but not for EVERY transaction. On my SB method I also tried to decorate the method with the following annotation
<pre>
@Transaction(isolation = Isolation.READ_UNCOMMITTED)
</pre>
but that doesn't see to have done anything. I next tried, via the portlet that is calling the service to READ the records to wrap the call in a TransactionInvokerUtil callable. Again, no joy with this approach. I think started to think that perhaps it had something to do with the fact that my server method definition is using a Dynamic Query and that maybe, though this was a long shot, the annotation declarations for how to treat the transaction don't carry over to the dynamic query -- but I don't know that this actually makes sense. So -- now I have no idea where to do from here. Is my theory correct and they just don't apply to DQs? Should I instead change this method to use a custom sql via a custom Finder class? Any help/suggestions are welcome -- just rubber ducking with me and sharing your thoughts would help as well.
I'm totally stuck on this one so I am hoping one of the community AllStars can help me out here. My scenario is this. I have a portlet on a page. When the users leaves the page, the "unload" event that the browser fires causes a Resource call for my portlet. My Resource Command class is hit at which point I either update or add a record using my XXXLocalService sb class. The user then navigates to the other page. If they navigate to a page with a separate portlet that also uses the XXXLocalService sb class, they're not seeing the last add/update that was just made. I can see the row in the table but I am guessing that it is not yet committed. The default isolation is READ_COMMITTED so it makes sense that the update is not seen. To prove this theory I activated a property in the portal-ext
<pre>
jdbc.default.defaultTransactionIsolation=READ_UNCOMMITTED
</pre>
When I set this and restart my portal, then I have no issues -- except for the fact that all transactions are not in a "dirty mode" and that it could create strange behaviour under load -- I'm fine with a READ_UNCOMMITTED transaction, but not for EVERY transaction. On my SB method I also tried to decorate the method with the following annotation
<pre>
@Transaction(isolation = Isolation.READ_UNCOMMITTED)
</pre>
but that doesn't see to have done anything. I next tried, via the portlet that is calling the service to READ the records to wrap the call in a TransactionInvokerUtil callable. Again, no joy with this approach. I think started to think that perhaps it had something to do with the fact that my server method definition is using a Dynamic Query and that maybe, though this was a long shot, the annotation declarations for how to treat the transaction don't carry over to the dynamic query -- but I don't know that this actually makes sense. So -- now I have no idea where to do from here. Is my theory correct and they just don't apply to DQs? Should I instead change this method to use a custom sql via a custom Finder class? Any help/suggestions are welcome -- just rubber ducking with me and sharing your thoughts would help as well.
Problem solved and in the end it had nothing to do with transactions. Here is what I did --I set a break point in my portlets render method but then a second one in my service (builder service). When I clicked a link that triggered the onunload browser event I noticed that the portlet render method ran first, but then a closer inspection made me realize that they were actually running on separate threads. So even though I am making a synchronous resource call, that doesn't seem to matter. In the end I changed the event I'm listening to from onunload to onbeforeunload and that seems to have solved the problem for me. I have read some documentation that suggests that it might not be supported on all browsers, but so far, with the mainstream ones at least, all seems to be working as expected. Hopefully this helps someone else in the future.