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

If service.xml contains compound primary key, the generated code does not compile

    Details

      Description

      Since LPS-29025 there is an extra logic in model_impl.ftl to get the default import locale:

      @Override
      		public void prepareLocalizedFieldsForImport() throws LocaleException {
      			Locale defaultLocale = LocaleUtil.fromLanguageId(
      				getDefaultLanguageId());
      
      			Locale[] availableLocales = LocaleUtil.fromLanguageIds(
      				getAvailableLanguageIds());
      
      			Locale defaultImportLocale = LocalizationUtil.getDefaultImportLocale(
      				${entity.name}.class.getName(), getPrimaryKey(), defaultLocale,
      				availableLocales);
      
      			prepareLocalizedFieldsForImport(defaultImportLocale);
      		}
      

      The getPrimaryKey() should return a long value here, but if the entity has a compound index, it will return an entityPK object instead of a long:

      @Override
      	public ${entity.PKClassName} getPrimaryKey() {
      		<#if entity.hasCompoundPK()>
      			return new ${entity.PKClassName}(
      
      			<#list entity.PKList as column>
      				_${column.name}
      
      				<#if column_has_next>
      					,
      				</#if>
      			</#list>
      
      			);
      		<#else>
      			return _${entity.PKList[0].name};
      		</#if>
      	}
      

      This will cause the generated code to not compile due to :

      /Users/vili/workspace/liferay/7.0/liferay-workspace/modules/sb-pk/sb-pk-service/src/main/java/com/liferay/support/poc/sb/model/impl/EmailContentModelImpl.java:490: error: incompatible types: EmailContentPK cannot be converted to long
                                      getPrimaryKey(), defaultLocale, availableLocales);
                                                   ^
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                support-lep@liferay.com SE Support
                Reporter:
                istvan.sajtos Istvan Sajtos
                Participants of an Issue:
                Recent user:
                Raven Song
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  1 year, 28 weeks, 2 days ago

                  Packages

                  Version Package