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

"Duplicate entry for key 'ix_103d6207'" is thrown when upgrading from 6.2 to master

    Details

      Description

      Steps to reproduce

      1. Create a structure with a repeatable image field
      2. Create a template related to created structure
      3. Create a webcontent using created structure, adding 3 o 4 images
      4. Update from 6.2 to 7.0
        • Wrong behavior: following exception is thrown and JournalArticle is not updated
          11:54:32,602 INFO  [localhost-startStop-1][UpgradeProcess:79] Upgrading com.liferay.journal.upgrade.v1_0_0.UpgradeJournalArticleImage
          INFO - Upgrading com.liferay.journal.upgrade.v1_0_0.UpgradeJournalArticleImage
          11:54:32,604 INFO  [localhost-startStop-1][UpgradeProcess:94] Completed upgrade process com.liferay.journal.upgrade.v1_0_0.UpgradeJournalArticleImage in 2ms
          INFO - Completed upgrade process com.liferay.journal.upgrade.v1_0_0.UpgradeJournalArticleImage in 2ms
          11:54:32,606 ERROR [localhost-startStop-1][com_liferay_portal_upgrade:96] Invocation to listener threw exception
          java.lang.RuntimeException: com.liferay.portal.kernel.upgrade.UpgradeException: org.postgresql.util.PSQLException: ERROR: llave duplicada viola restricción de unicidad «ix_103d6207»_  Detail: Ya existe la llave (groupid, articleid, version, elinstanceid, elname, languageid)=(20182, 20597, 1, , Image1786, _en_US). [Sanitized]
                  at com.liferay.portal.upgrade.internal.release.ReleaseManager$UpgradeInfosRunnable.run(ReleaseManager.java:354)
                  at com.liferay.portal.output.stream.container.OutputStreamContainerFactoryTracker.runWithSwappedLog(OutputStreamContainerFactoryTracker.java:100)
                  at com.liferay.portal.upgrade.internal.release.ReleaseManager.executeUpgradeInfos(ReleaseManager.java:193)
                  at com.liferay.portal.upgrade.internal.release.ReleaseManager.doExecute(ReleaseManager.java:177)
          
          [...]
          
                  at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1777)
                  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
                  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
                  at java.lang.Thread.run(Thread.java:745)
          Caused by: com.liferay.portal.kernel.upgrade.UpgradeException: org.postgresql.util.PSQLException: ERROR: llave duplicada viola restricción de unicidad «ix_103d6207»_  Detail: Ya existe la llave (groupid, articleid, version, elinstanceid, elname, languageid)=(20182, 20597, 1, , Image1786, _en_US). [Sanitized]
                  at com.liferay.portal.kernel.upgrade.UpgradeProcess.upgrade(UpgradeProcess.java:88)
                  at com.liferay.portal.kernel.upgrade.UpgradeProcess.upgrade(UpgradeProcess.java:119)
                  at com.liferay.portal.upgrade.internal.release.ReleaseManager$UpgradeInfosRunnable.run(ReleaseManager.java:333)
                  ... 93 more
          Caused by: org.postgresql.util.PSQLException: ERROR: llave duplicada viola restricción de unicidad «ix_103d6207»_  Detail: Ya existe la llave (groupid, articleid, version, elinstanceid, elname, languageid)=(20182, 20597, 1, , Image1786, _en_US). [Sanitized]
                  at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
                  at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
                  at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
                  at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
                  at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
                  at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:413)
                  at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44)
                  at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java)
                  at com.liferay.journal.upgrade.v1_0_0.UpgradeJournalArticleImage.updateJournalArticle(UpgradeJournalArticleImage.java:47)
                  at com.liferay.journal.upgrade.v1_0_0.UpgradeJournalArticleImage.updateJournalArticleImages(UpgradeJournalArticleImage.java:74)
                  at com.liferay.journal.upgrade.v1_0_0.UpgradeJournalArticleImage.doUpgrade(UpgradeJournalArticleImage.java:31)
                  at com.liferay.portal.kernel.upgrade.UpgradeProcess.upgrade(UpgradeProcess.java:85)
                  ... 95 more
          
        • Expected behavior: JournalArticle is updated succesfully

      Problem is caused by LPS-62881.

      At 6.2, we have an repeatable image field, so we have more than one entry at JournalArticleImage for each with:

      • elinstanceid = "blank"
      • elname = <image_field_name>_<number>
        articleimageid groupid articleid version elinstanceid elname languageid tempimage
        1497543 1119421 1497540 1   ImageList_0 _es_ES f
        1497545 1119421 1497540 1   ImageList_1   f
        1497544 1119421 1497540 1   ImageList_1 _es_ES f
        1497559 1119421 1497540 1   ImageList_2 _es_ES f
        1497560 1119421 1497540 1   ImageList_3 _es_ES f
        1518214 1119421 1497540 1.1   ImageList_0 _es_ES f
        1518215 1119421 1497540 1.1   ImageList_1 _es_ES f
        1518216 1119421 1497540 1.1   ImageList_2 _es_ES f
        1518217 1119421 1497540 1.1   ImageList_3 _es_ES f
        1518217 1119421 1497540 1.1   ImageList_3 _es_ES f

      But at UpgradeJournalArticleImage we are trying to remove the trailing "_<number>" for each one, so a duplicate entry error at database level is thrown.

      Problematic code

      	protected void updateJournalArticleImages() throws Exception {
      		PreparedStatement ps = null;
      		ResultSet rs = null;
      
      		try {
      			ps = connection.prepareStatement(
      				"select articleImageId, elName from JournalArticleImage");
      
      			rs = ps.executeQuery();
      
      			while (rs.next()) {
      				long articleImageId = rs.getLong(1);
      				String elName = rs.getString(2);
      
      				int lastIndexOf = elName.lastIndexOf(StringPool.UNDERLINE);
      
      				if (lastIndexOf > 0) {
      					elName = elName.substring(0, lastIndexOf);
      				}
      
      				updateJournalArticle(articleImageId, elName);
      			}
      		}
      		finally {
      			DataAccess.cleanUp(ps, rs);
      		}
      	}
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  4 years, 7 weeks ago

                  Packages

                  Version Package
                  7.0.0 CE RC1