You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: java/cds-data.md
+87-16
Original file line number
Diff line number
Diff line change
@@ -512,48 +512,119 @@ See the following example:
512
512
entity Equity {
513
513
@cds.java.name : 'clazz'
514
514
class : String;
515
-
...
516
515
}
517
516
```
518
517
519
518
```java
520
519
interfaceEquity {
520
+
521
+
@CdsName("class")
521
522
StringgetClazz();
522
523
524
+
@CdsName("class")
523
525
voidsetClazz(Stringclazz);
524
-
...
526
+
525
527
}
526
528
```
527
529
528
530
#### Renaming Types in Java
529
531
530
-
You might also want to rename the type of the entity. For this you can use annotation `@cds.java.this.name` to specify alternative name for the accessor interfaces and [static model](./cqn-services/persistence-services#staticmodel) interfaces. This annotation can be used only on definitions and is ignored everywhere else.
532
+
For entities and types it is recommended to use `@cds.java.this.name` to specify an alternative name for the accessor interfaces and [static model](./cqn-services/persistence-services#staticmodel) interfaces.
533
+
The annotation `@cds.java.this.name` - in contrast to `@cds.java.name` - is not propagated, along projections, includes or from types to elements.
531
534
532
-
See the following example:
535
+
::: warning Unexpected effects of `@cds.java.name` on entities and types
536
+
The annotation propagation behaviour applied to `@cds.java.name` can have unexpected side effects when used to rename entities or types,
537
+
as it is propagated along projections, includes or from structured types to (flattened) elements. Nevertheless it might be useful in simple 1:1-projection scenarios,
538
+
where the base entity and the projected entity should be renamed in the same way.
539
+
:::
540
+
541
+
See the following example, renaming an entity:
533
542
534
543
```cds
535
-
@cds.java.this.name: 'MyJavaClass'
536
-
entity Class {
537
-
key ID: String;
544
+
@cds.java.this.name: 'Book'
545
+
entity Books {
546
+
// ...
538
547
}
539
548
```
540
549
541
550
```java
542
-
@CdsName("javaNames.Class")
543
-
publicinterfaceMyJavaClassextendsCdsData {
544
-
StringID="ID";
551
+
@CdsName("Books")
552
+
publicinterfaceBookextendsCdsData {
553
+
// ...
554
+
}
555
+
```
545
556
546
-
@CdsName(ID)
547
-
Stringid();
557
+
Here is another example, renaming a type:
548
558
549
-
@CdsName(ID)
550
-
MyJavaClassid(Stringid);
559
+
```cds
560
+
@cds.java.this.name: 'MyName'
561
+
type Name {
562
+
firstName: String;
563
+
lastName: String;
564
+
}
565
+
566
+
entity Person {
567
+
publicName: Name;
568
+
secretName: Name;
569
+
}
570
+
```
571
+
572
+
```java
573
+
@CdsName("Name")
574
+
publicinterfaceMyNameextendsCdsData {
575
+
// ...
576
+
}
551
577
552
-
// rest of the interface
578
+
@CdsName("Person")
579
+
publicinterfacePersonextendsCdsData {
580
+
StringPUBLIC_NAME="publicName";
581
+
StringSECRET_NAME="secretName";
582
+
583
+
MyNamegetPublicName();
584
+
voidsetPublicName(MyNamepublicName);
585
+
586
+
MyNamegetSecretName();
587
+
voidsetSecretName(MyNamesecretName);
588
+
}
589
+
```
590
+
591
+
::: details See how the previous example would turn out with `@cds.java.name`
592
+
593
+
```cds
594
+
@cds.java.name: 'MyName'
595
+
type Name {
596
+
firstName: String;
597
+
lastName: String;
598
+
}
599
+
600
+
entity Person {
601
+
publicName: Name;
602
+
secretName: Name;
553
603
}
554
604
```
555
605
556
-
In contrast with the annotation `@cds.java.name`, the annotation `@cds.java.this.name` does not rename projections of the annotated entity. If you want to rename chain of entities, you must annotate each of them individually.
606
+
```java
607
+
@CdsName("Name")
608
+
publicinterfaceMyNameextendsCdsData {
609
+
// ...
610
+
}
611
+
612
+
@CdsName("Person")
613
+
publicinterfacePersonextendsCdsData {
614
+
StringMY_NAME="publicName";
615
+
StringMY_NAME="secretName";
616
+
617
+
MyNamegetMyName();
618
+
voidsetMyName(MyNamemyName);
619
+
620
+
MyNamegetMyName();
621
+
voidsetMyName(MyNamemyName);
622
+
}
623
+
```
624
+
625
+
Note, that the propagated annotation `@cds.java.name` creates attribute and method conflicts in `Person`.
626
+
627
+
:::
557
628
558
629
::: warning
559
630
This feature requires version 8.2.0 of the [CDS Command Line Interface](/tools/cds-cli).
Copy file name to clipboardexpand all lines: java/cqn-services/persistence-services.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -579,7 +579,7 @@ See [Class JdbcTemplate](https://docs.spring.io/spring-framework/docs/current/ja
579
579
The static model and accessor interfaces can be generated using the [CDS Maven Plugin](../developing-applications/building#cds-maven-plugin).
580
580
581
581
::: warning _❗ Warning_
582
-
Currently, the generator doesn't support using reserved [Java keywords](https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.9) as identifiers in the CDS model. Conflicting element names can be renamed in Java using the [@cds.java.name](../cds-data#renaming-elements-in-java) annotation. For entities, you can use [@cds.java.this.name](../cds-data#renaming-types-in-java).
582
+
Currently, the generator doesn't support using reserved [Java keywords](https://docs.oracle.com/javase/specs/jls/se13/html/jls-3.html#jls-3.9) as identifiers in the CDS model. Conflicting element names can be renamed in Java using the [@cds.java.name](../cds-data#renaming-elements-in-java) annotation. For entities it is recommended to use [@cds.java.this.name](../cds-data#renaming-types-in-java).
0 commit comments