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

StaleObjectStateException when trying to update a Contact

    Details

      Description

      Hi,

      A StaleObjectStateException will be shown in logs when a service try to update a Contact that are not equals than Contact saved into hibernate session:

      com.liferay.portal.kernel.exception.SystemException: com.liferay.portal.kernel.dao.orm.ORMException: {mvccVersion=317, contactId=8367818, companyId=10136, userId=8367817, userName=, createDate=Mon Jan 18 18:01:19 CET 2016, modifiedDate=Tue Oct 09 05:27:01 CEST 2018, classNameId=10047, classPK=8367817, accountId=10138, parentContactId=0, emailAddress=XXXX@XXXX.XX, firstName=XXXXX, middleName=, lastName=XXXX XXXXX, prefixId=1, suffixId=2, male=true, birthday=Fri Dec 22 00:00:00 CET 1967, smsSn=, facebookSn=, jabberSn=, skypeSn=, twitterSn=, employeeStatusId=, employeeNumber=, jobTitle=XXXXX, jobClass=, hoursOfOperation=} is stale in comparison to {mvccVersion=318, contactId=8367818, companyId=10136, userId=8367817, userName=, createDate=2016-01-18 18:01:19.636, modifiedDate=2018-10-09 05:27:01.7, classNameId=10047, classPK=8367817, accountId=10138, parentContactId=0, emailAddress=XXXX@XXXX.XX, firstName=XXXXX, middleName=, lastName=XXXX XXXXX, prefixId=1, suffixId=2, male=true, birthday=1967-12-22 00:00:00.0, smsSn=, facebookSn=, jabberSn=, skypeSn=, twitterSn=, employeeStatusId=, employeeNumber=, jobTitle=XXXXX, jobClass=, hoursOfOperation=}
      at com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl.processException(BasePersistenceImpl.java:270)
      	at com.liferay.portal.service.persistence.impl.ContactPersistenceImpl.updateImpl(ContactPersistenceImpl.java:1857)
      	at com.liferay.portal.service.persistence.impl.ContactPersistenceImpl.updateImpl(ContactPersistenceImpl.java:67)
      	at com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl.update(BasePersistenceImpl.java:352)
      	at com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl.update(BasePersistenceImpl.java:371)
      	at com.liferay.portal.service.impl.UserLocalServiceImpl.updateUser(UserLocalServiceImpl.java:5368)
      	at sun.reflect.GeneratedMethodAccessor796.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      ...
      Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.liferay.portal.model.impl.ContactImpl#8367818]
      	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:241)
      	... 208 more
      

      This behavior can be reproduced using the attached Groovy script that trying to fetch, update and update again the same Contact. This script will reproduce this issue due to Contact, for the last update, is different than current Contact saved in hibernate session when it's fetched and updated for the first time. To use this script, an initialization for long contactId = -1L; needs to be done with an existing contactId from Contact table.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  48 weeks, 1 day ago

                  Packages

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