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

Possible StaleObjectStateException when creating a user

    Details

      Description

      A StaleObjectStateException will be thrown if session cache (first level hibernate cache) does not contain the latest version of the user object and this latest version is going to be updated:

      Here, for example, the exception is thrown when the above conditions take place:

      2018-08-30 12:25:06.265 ERROR [http-nio-8080-exec-5][PortletServlet:112] javax.portlet.PortletException: com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: {mvccVersion=0, uuid=66df11f2-b57b-aaed-bbab-55fe60a71165, externalReferenceCode=, userId=36465, companyId=20099, createDate=Thu Aug 30 12:25:05 CEST 2018, modifiedDate=Thu Aug 30 12:25:06 CEST 2018, defaultUser=false, contactId=36466, password=, passwordEncrypted=true, passwordReset=true, passwordModifiedDate=null, digest=, reminderQueryQuestion=, reminderQueryAnswer=, graceLoginCount=0, screenName=cris, emailAddress=cristina@liferay.com, facebookId=0, googleUserId=, ldapServerId=-1, openId=, portraitId=0, languageId=en_US, timeZoneId=UTC, greeting=Welcome cris tinita!, comments=, firstName=cris, middleName=, lastName=tinita, jobTitle=, loginDate=null, loginIP=, lastLoginDate=null, lastLoginIP=, lastFailedLoginDate=null, failedLoginAttempts=0, lockout=false, lockoutDate=null, agreedToTermsOfUse=false, emailAddressVerified=false, status=2} is stale in comparison to {mvccVersion=1, uuid=66df11f2-b57b-aaed-bbab-55fe60a71165, externalReferenceCode=, userId=36465, companyId=20099, createDate=2018-08-30 12:25:05.709, modifiedDate=2018-08-30 12:25:06.033, defaultUser=false, contactId=36466, password=AAAAoAAB9ADyrmlzf/eD8h9g0D2ZKYkUUN1Xy8qP96hrbBUp, passwordEncrypted=true, passwordReset=true, passwordModifiedDate=2018-08-30 12:25:05.91, digest=, reminderQueryQuestion=, reminderQueryAnswer=, graceLoginCount=0, screenName=cris, emailAddress=cristina@liferay.com, facebookId=0, googleUserId=, ldapServerId=-1, openId=, portraitId=0, languageId=en_US, timeZoneId=UTC, greeting=Welcome cris tinita!, comments=, firstName=cris, middleName=, lastName=tinita, jobTitle=, loginDate=null, loginIP=, lastLoginDate=null, lastLoginIP=, lastFailedLoginDate=null, failedLoginAttempts=0, lockout=false, lockoutDate=null, agreedToTermsOfUse=false, emailAddressVerified=false, status=0}
      javax.portlet.PortletException: com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: {mvccVersion=0, uuid=66df11f2-b57b-aaed-bbab-55fe60a71165, externalReferenceCode=, userId=36465, companyId=20099, createDate=Thu Aug 30 12:25:05 CEST 2018, modifiedDate=Thu Aug 30 12:25:06 CEST 2018, defaultUser=false, contactId=36466, password=, passwordEncrypted=true, passwordReset=true, passwordModifiedDate=null, digest=, reminderQueryQuestion=, reminderQueryAnswer=, graceLoginCount=0, screenName=cris, emailAddress=cristina@liferay.com, facebookId=0, googleUserId=, ldapServerId=-1, openId=, portraitId=0, languageId=en_US, timeZoneId=UTC, greeting=Welcome cris tinita!, comments=, firstName=cris, middleName=, lastName=tinita, jobTitle=, loginDate=null, loginIP=, lastLoginDate=null, lastLoginIP=, lastFailedLoginDate=null, failedLoginAttempts=0, lockout=false, lockoutDate=null, agreedToTermsOfUse=false, emailAddressVerified=false, status=2} is stale in comparison to {mvccVersion=1, uuid=66df11f2-b57b-aaed-bbab-55fe60a71165, externalReferenceCode=, userId=36465, companyId=20099, createDate=2018-08-30 12:25:05.709, modifiedDate=2018-08-30 12:25:06.033, defaultUser=false, contactId=36466, password=AAAAoAAB9ADyrmlzf/eD8h9g0D2ZKYkUUN1Xy8qP96hrbBUp, passwordEncrypted=true, passwordReset=true, passwordModifiedDate=2018-08-30 12:25:05.91, digest=, reminderQueryQuestion=, reminderQueryAnswer=, graceLoginCount=0, screenName=cris, emailAddress=cristina@liferay.com, facebookId=0, googleUserId=, ldapServerId=-1, openId=, portraitId=0, languageId=en_US, timeZoneId=UTC, greeting=Welcome cris tinita!, comments=, firstName=cris, middleName=, lastName=tinita, jobTitle=, loginDate=null, loginIP=, lastLoginDate=null, lastLoginIP=, lastFailedLoginDate=null, failedLoginAttempts=0, lockout=false, lockoutDate=null, agreedToTermsOfUse=false, emailAddressVerified=false, status=0}
       at com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand.processAction(BaseMVCActionCommand.java:69)
       at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.callActionMethod(MVCPortlet.java:378)
       at com.liferay.portal.kernel.portlet.LiferayPortlet.processAction(LiferayPortlet.java:97)
       at com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet.processAction(MVCPortlet.java:260)
       at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:77)
       at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:50)
       at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:108)
       { .... }
      Caused by: com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: {mvccVersion=0, uuid=66df11f2-b57b-aaed-bbab-55fe60a71165, externalReferenceCode=, userId=36465, companyId=20099, createDate=Thu Aug 30 12:25:05 CEST 2018, modifiedDate=Thu Aug 30 12:25:06 CEST 2018, defaultUser=false, contactId=36466, password=, passwordEncrypted=true, passwordReset=true, passwordModifiedDate=null, digest=, reminderQueryQuestion=, reminderQueryAnswer=, graceLoginCount=0, screenName=cris, emailAddress=cristina@liferay.com, facebookId=0, googleUserId=, ldapServerId=-1, openId=, portraitId=0, languageId=en_US, timeZoneId=UTC, greeting=Welcome cris tinita!, comments=, firstName=cris, middleName=, lastName=tinita, jobTitle=, loginDate=null, loginIP=, lastLoginDate=null, lastLoginIP=, lastFailedLoginDate=null, failedLoginAttempts=0, lockout=false, lockoutDate=null, agreedToTermsOfUse=false, emailAddressVerified=false, status=2} is stale in comparison to {mvccVersion=1, uuid=66df11f2-b57b-aaed-bbab-55fe60a71165, externalReferenceCode=, userId=36465, companyId=20099, createDate=2018-08-30 12:25:05.709, modifiedDate=2018-08-30 12:25:06.033, defaultUser=false, contactId=36466, password=AAAAoAAB9ADyrmlzf/eD8h9g0D2ZKYkUUN1Xy8qP96hrbBUp, passwordEncrypted=true, passwordReset=true, passwordModifiedDate=2018-08-30 12:25:05.91, digest=, reminderQueryQuestion=, reminderQueryAnswer=, graceLoginCount=0, screenName=cris, emailAddress=cristina@liferay.com, facebookId=0, googleUserId=, ldapServerId=-1, openId=, portraitId=0, languageId=en_US, timeZoneId=UTC, greeting=Welcome cris tinita!, comments=, firstName=cris, middleName=, lastName=tinita, jobTitle=, loginDate=null, loginIP=, lastLoginDate=null, lastLoginIP=, lastFailedLoginDate=null, failedLoginAttempts=0, lockout=false, lockoutDate=null, agreedToTermsOfUse=false, emailAddressVerified=false, status=0}
       at com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl.processException(BasePersistenceImpl.java:270)
       at com.liferay.portal.service.persistence.impl.UserPersistenceImpl.updateImpl(UserPersistenceImpl.java:8495)
       at com.liferay.portal.service.persistence.impl.UserPersistenceImpl.updateImpl(UserPersistenceImpl.java:88)
       at com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl.update(BasePersistenceImpl.java:357)
       { ... }
      Caused by: com.liferay.portal.kernel.dao.orm.ORMException: {mvccVersion=0, uuid=66df11f2-b57b-aaed-bbab-55fe60a71165, externalReferenceCode=, userId=36465, companyId=20099, createDate=Thu Aug 30 12:25:05 CEST 2018, modifiedDate=Thu Aug 30 12:25:06 CEST 2018, defaultUser=false, contactId=36466, password=, passwordEncrypted=true, passwordReset=true, passwordModifiedDate=null, digest=, reminderQueryQuestion=, reminderQueryAnswer=, graceLoginCount=0, screenName=cris, emailAddress=cristina@liferay.com, facebookId=0, googleUserId=, ldapServerId=-1, openId=, portraitId=0, languageId=en_US, timeZoneId=UTC, greeting=Welcome cris tinita!, comments=, firstName=cris, middleName=, lastName=tinita, jobTitle=, loginDate=null, loginIP=, lastLoginDate=null, lastLoginIP=, lastFailedLoginDate=null, failedLoginAttempts=0, lockout=false, lockoutDate=null, agreedToTermsOfUse=false, emailAddressVerified=false, status=2} is stale in comparison to {mvccVersion=1, uuid=66df11f2-b57b-aaed-bbab-55fe60a71165, externalReferenceCode=, userId=36465, companyId=20099, createDate=2018-08-30 12:25:05.709, modifiedDate=2018-08-30 12:25:06.033, defaultUser=false, contactId=36466, password=AAAAoAAB9ADyrmlzf/eD8h9g0D2ZKYkUUN1Xy8qP96hrbBUp, passwordEncrypted=true, passwordReset=true, passwordModifiedDate=2018-08-30 12:25:05.91, digest=, reminderQueryQuestion=, reminderQueryAnswer=, graceLoginCount=0, screenName=cris, emailAddress=cristina@liferay.com, facebookId=0, googleUserId=, ldapServerId=-1, openId=, portraitId=0, languageId=en_US, timeZoneId=UTC, greeting=Welcome cris tinita!, comments=, firstName=cris, middleName=, lastName=tinita, jobTitle=, loginDate=null, loginIP=, lastLoginDate=null, lastLoginIP=, lastFailedLoginDate=null, failedLoginAttempts=0, lockout=false, lockoutDate=null, agreedToTermsOfUse=false, emailAddressVerified=false, status=0}
       at com.liferay.portal.dao.orm.hibernate.ExceptionTranslator.translate(ExceptionTranslator.java:47)
       at com.liferay.portal.dao.orm.hibernate.SessionImpl.merge(SessionImpl.java:226)
       at com.liferay.portal.kernel.dao.orm.ClassLoaderSession.merge(ClassLoaderSession.java:394)
       at com.liferay.portal.service.persistence.impl.UserPersistenceImpl.updateImpl(UserPersistenceImpl.java:8491)
       ... 207 more
      Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.liferay.portal.model.impl.UserImpl#36465]
       at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:485)
       at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:255)
       at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84)
       at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867)
       at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851)
       at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855)
       at com.liferay.portal.dao.orm.hibernate.SessionImpl.merge(SessionImpl.java:223)
       ... 209 more

       

      It is easily reproducible with the script attached, which registers a custom UserModelListener that removes the user from session cache before updating it. It simulates the possible situation in which the object passed as argument (that is going to be updated) is not the same as the cached and returned one (in this example the cache will be empty). In this case, having the same latest changes as the ones that Hibernate is going to persist is needed to retrieve the returned object from the persistence layer.

      Steps to reproduce:

      1. Execute the groovy script attached. It removes the user from session cache before updating the user.
      2. Create a new user.

      Expected behaviour :

      The user is created correctly.

      Current behaviour :

      A StaleObjectStateException is thrown.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  1 year, 5 days ago

                  Packages

                  Version Package
                  7.0.0 DXP FP59
                  7.0.0 DXP SP9
                  7.0.X
                  7.1.10 DXP FP3
                  7.1.1 CE GA2
                  7.1.10.1 SP1
                  7.1.X
                  Master