Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-80504

ModelListener Caching Bug at onBeforeAddAssociation

    Details

    • JDK:
      Oracle Sun JDK 8
    • Application Servers:
      Apache Tomcat 7.0
    • Databases:
      HSQLDB 2
    • Device Type:
      Desktop

      Description

      Use case:

      • Create a model listener for the user model
        public class BugDemoModelListener extends BaseModelListener<User>
      • Override onBeforeAddAssociation method
      • Access the old user roles (before the new one is added)

      Expected behaviour:

      • You can access the old user roles and perform some custom logic without any effects

      Current behaviour:

      • As soon as you call user.getRoles() from the onBeforeAddAssociation method the gui of the control panel -> edit user -> roles doesn't show the newly added role. You have to restart the server because the cache was cleared at the wrong time.

      Workaround:

      • If you want to access the user roles (even if it's just for System.outs) in the onBeforeAddAssociation method you have to manually clear the cache so that the control panel gui is showing the newly added role as expected:
      PortalCache<Long, long[]> portalCacheRTL = MultiVMPoolUtil.getCache(
           TableMapper.class.getName() + "-Users_Roles-RightToLeft");
      portalCacheRTL.remove(user.getUserId());
      

      This could also effect the caching of all other associations (not just for user roles)!

        Attachments

          Activity

            People

            • Assignee:
              support-lep@liferay.com SE Support
              Reporter:
              oli_bayer Oliver Bayer
              Participants of an Issue:
              Recent user:
              Oliver Bayer
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Days since last comment:
                1 year, 24 weeks ago

                Packages

                Version Package