RWS / dxa-modules

SDL Digital Experience Accelerator Modules
Apache License 2.0
8 stars 16 forks source link

Ambiguous semantic mapping error if “entityName” is same as entity class name #31

Open rpakira opened 5 years ago

rpakira commented 5 years ago

We are facing issue to map some Tridion component field data to EntityModel object. Some components link fields can be linked to different type of components. So, we have used generic type, EntityModel type of field in the SemanticEntity to map data of the linked component. But some of the components are throwing following error:

Caused by: com.sdl.webapp.common.api.mapping.semantic.SemanticMappingException: Ambiguous semantic mapping for …

I have investigated the issue and found that DXA framework is failing to map linked component data to EntityModel object if entities for linked component have “entityName” attribute value same as the class name. As the mapping shown below:

@SemanticEntity(entityName = "**Product**", vocabulary = SDL_CORE, prefix = "p")
public class **Product** extends AbstractEntityModel {
…
}

But if we put “entityName” different from class name, as shown below then it is working.

@SemanticEntity(entityName = "**Product**", vocabulary = SDL_CORE, prefix = "p")
public class **ProductObject** extends AbstractEntityModel {
…
}

The issue is occurring because DXA framework register both the value that is specified in “entityName” attribute and entity class name as entity. If both the values are same, then DXA framework finds ambiguous semantic mapping (unable to find unique matching entity for model data) and throws exception.

Can you please let me know if it is limitation of DXA framework or we should follow some naming convention for class name and “entityName” attribute?

rpannekoek commented 5 years ago

Hi. Thanks for reporting this issue. Two process remarks:

Regarding your question: by default, DXA uses the class name as entity name (in the Core Vocabulary). If that default mapping is fine for you, you don't have to add a @SemanticEntity annotation at all (at least not for the Core Vocabulary).

On the other hand, if you do add such a (superfluous) annotation, I would expect it to be silently ignored rather than yielding an "ambiguous semantic mapping" error. So, this sounds like a (minor) defect in the DXA Java Framework implementatation, with an easy work-around.

rpakira commented 5 years ago

Thank you very much for your suggestion.