Legacy Knowledge Base
Published Jun. 30, 2025

ObjectFieldNameException$MustNotBeDuplicate when updating Object Definition

Written By

Fabian Bouché

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack" publication program, made available for informational purposes. Articles in this program were published without a requirement for independent editing or verification and are provided"as is" without guarantee.

Before using any information from this article, independently verify its suitability for your situation and project.

Issue

  • When trying to update an object definition from one environment (eg. dev) to the other (eg. uat), the process fails with the following error:
com.liferay.object.exception.ObjectFieldNameException$MustNotBeDuplicate: Duplicate name objectFieldName
at com.liferay.object.service.impl.ObjectFieldLocalServiceImpl._validateName(ObjectFieldLocalServiceImpl.java:1407) ~[?:?]
at com.liferay.object.service.impl.ObjectFieldLocalServiceImpl._addObjectField(ObjectFieldLocalServiceImpl.java:813) ~[?:?]
at com.liferay.object.service.impl.ObjectFieldLocalServiceImpl.addCustomObjectField(ObjectFieldLocalServiceImpl.java:136) ~[?:?]

Environment

  • Liferay DXP 7.4

Resolution

  • Make sure the fields which have the same name in the source and target environment also have the same externalReferenceCode.
  • As of DXP 7.4 2024.Q1, the externalReferenceCode of an object field cannot be consulted or updated from the Object Definition GUI. You have to use the ObjectDefinition API.

APIs to use:

  • Use this API in both environments to get the objectFieldId's for each fields of an Object Definition using its objectDefinitionId (xxxxx):
GET /o/object-admin/v1.0/object-definitions/xxxxx

 

  • Use this API in both environments to read the externalReferenceCode of an Object Field given its objectFieldId (yyyyy):
GET /o/object-admin/v1.0/object-fields/yyyyy

 

  • And eventually, use this API in the source environment to patch the externalReferenceCode of an Object Field given its objectFieldId (yyyyy) so that it matches the targets:
PATCH /o/object-admin/v1.0/object-fields/yyyyy

 

with the following body:

{
"externalReferenceCode": "70c0d71c-ba78-f4df-61b8-4db5e4ba8aeb"
}

As soon as object fields with the same name have matching external reference codes in both environments, you can try again.

 

Additional Information

Most of the time, this issue is not supposed to happen. However, here is a typical scenario where the issue will happen:

  • An object definition is created in dev, exported and imported in uat. At this point, all fields have the same externalReferenceCode in both environments.
  • A new field is added manually in both environments, they will have a different random externalReferenceCode.
  • The next time you are going to import the object definition from dev to uat, the update will fail because of the manually added field unless you update it using the API so that they share the same externalReferenceCode.

 

 

Did this article resolve your issue ?

Legacy Knowledge Base