cancel
Showing results for 
Search instead for 
Did you mean: 

CAP CDS import leads to error "variable XYZ is already defined in interface"

tobias2022
Explorer
0 Kudos

Hello all,

I am trying to import the metadata of the official "Condition Contract API" into my Java CAP project. The my compile leads to the error message that the variable is already defined. And that for all entities. Im just using "cds import ../../api.edmx --as cds".

The problem is the following:

For example, the entity CndnContrConditionRecord has the key field "ConditionContract", which becomes "CONDITION_CONTRACT" when compiled. At the same time the entity has the field "_ConditionContract" which also becomes "CONDITION_CONTRACT". Now of course I have a problem.

Is there a trick here? Is this the way it is supposed to be? Is this a bug?

I used the annotation @cds.java.name in another API import, but in this API I have to adjust dozens of fields, and I can imagine that this leads to problems, especially that I want to use the naviogation features.

Thanks!

View Entire Topic
marcbecker
Contributor
0 Kudos

Hi Tobias,

unfortunately explicitly resolving the conflicts by using the annotation @cds.java.name is the only way to solve this easily at the moment. When using the interfaces this will not be a problem, because internally the methods will still be able to distinguish "ConditionContract" and "_ConditionContract". The Java method name is not really relevant there anymore.

Here is the link to the docs again for @cds.java.name: https://cap.cloud.sap/docs/java/data#renaming-elements-in-java

Best regards,
Marc

tobias2022
Explorer
0 Kudos

Thanks for the tip.

Maybe you can help me out a little here.

I want to include the following API: SAP API - Condition Contract

There I have, as already said, several places where I have to rename the navigation with @cds.java.name. I have done that. Now the project could be built with maven. After I included the API in my CDS service file (via using {... as ...} from ...) and expose a entity, the following Java file is created. As you can see, I now get the same string three times. And I am very sure that I defined the name only once... what am I doing wrong?

public interface CndnContrConditionRecord_ extends StructuredType<CndnContrConditionRecord_> {
String NAV_CNDN_CONTR_CNDN_RECD_VALIDITY = "_CndnContrCndnRecdValidity_ConditionContract";
String NAV_CNDN_CONTR_CNDN_RECD_VALIDITY = "_CndnContrCndnRecdValidity_ConditionRecord"; String NAV_CNDN_CONTR_CNDN_RECD_VALIDITY = "_CndnContrCndnRecdValidity_ConditionValidityEndDate";

And of cource I'm getting an error here... 😉
Sorry, for the formatting. The editor is... takes some time getting used to.Tobias
marcbecker
Contributor
0 Kudos

Hm, might be a bug in our code generator. Can you upload the modified imported CDS file (with the @cds.java.name annotations), so that I can try to reproduce this?

tobias2022
Explorer
0 Kudos

Sure. I uploaded it here.

I have replaced all leading _ in the Associations with Nav*.

marcbecker
Contributor
0 Kudos

I couldn't reproduce the issue unfortunately after adding the CDS file to srv/external and including it using "using { API_CONDITION_CONTRACT } from './external/API_CONDITION_CONTRACT';". Actually there are no String constants generated in the CndnContrConditionRecord_ class at all. Which CAP Java and @sap/cds-dk version are you using?

tobias2022
Explorer
0 Kudos

Thanks for testing. I have not yet switched to version 2.

CAP version 1.34.4

Maven plugin also 1.34

Cds-dk 6.5.0

If you are running the latest versions, I may have to upgrade.

marcbecker
Contributor
0 Kudos

Strange, also with CAP Java 1.34.4 and cds-dk 6.5.0 I am not able to reproduce the behaviour described by you. I also wouldn't have expected any difference in that area between CAP Java 1.x and 2.x. Do you provide any special settings to the "generate" goal of the CDS Maven Plugin?