<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: [CDS - SAP CAP for Java] Structure of Generated Java classes in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/cds-sap-cap-for-java-structure-of-generated-java-classes/qaa-p/12538118#M4700437</link>
    <description>&lt;P&gt;Thanks Adrian. I didn’t realize that auto-redirect would happen here.&lt;/P&gt;&lt;P&gt; &lt;BR /&gt;Since I annotated the ServiceItems entity as  @cds.persistence.skip, I started seeing runtime errors.&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jan 2022 08:46:21 GMT</pubDate>
    <dc:creator>rajendra3041-32</dc:creator>
    <dc:date>2022-01-17T08:46:21Z</dc:date>
    <item>
      <title>[CDS - SAP CAP for Java] Structure of Generated Java classes</title>
      <link>https://community.sap.com/t5/technology-q-a/cds-sap-cap-for-java-structure-of-generated-java-classes/qaq-p/12538116</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
  &lt;P&gt;I'm seeing a certain behaviour in the generated java classes for the CDS entities/service as modelled below - which I'm having a slightly tough time following. I've tried to explain it with a simple example below.&lt;/P&gt;
  &lt;P&gt;Start with the below entity and service models.&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;db/Orders.cds&lt;/STRONG&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;namespace ns;


entity Orders : cuid {
  customer : String;
  items    : Composition of many OrderItems on items.id = $self.id;
}

entity OrderItems : cuid {
  order    : Association to one Orders on order.id = $self.id;
  product  : String;
}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;STRONG&gt;srv/OrdersService.cds&lt;/STRONG&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;using {ns} from '../db/Orders';

service OrdersService {
  entity Orders as projection on ns.Orders;
}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Run &lt;STRONG&gt;&lt;/STRONG&gt;&lt;EM&gt;&lt;STRONG&gt;cds build --for java-cf&lt;/STRONG&gt; &lt;/EM&gt;in terminal. &lt;/P&gt;
  &lt;P&gt;Among the generated files in the &lt;STRONG&gt;Orders_&lt;/STRONG&gt; java class has a method &lt;STRONG&gt;items()&lt;/STRONG&gt; with return type as &lt;STRONG&gt;OrderItems_&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;srv/src/gen/java/cds/gen/ordersservice/Orders_.java:&lt;/STRONG&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;package cds.gen.ordersservice;&lt;BR /&gt;...&lt;BR /&gt;@CdsName("OrdersService.Orders")&lt;BR /&gt;public interface Orders_ extends StructuredType&amp;lt;Orders_&amp;gt; {&lt;BR /&gt;  String CDS_NAME = "OrdersService.Orders";&lt;BR /&gt;  ...&lt;BR /&gt;  OrderItems_ items();&lt;BR /&gt;  OrderItems_ items(Function&amp;lt;OrderItems_, CqnPredicate&amp;gt; filter);&lt;BR /&gt;}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Add a new entity in OrderService.cds&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;srv/OrdersService.cds&lt;/STRONG&gt;&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;using {ns} from '../db/Orders';

service OrdersService {
  entity Orders as projection on ns.Orders;

  @cds.persistence.skip
  entity ServiceItems : ns.OrderItems {
    faultCode  : String;
  }
}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The new ServiceItems entity &lt;EM&gt;extends &lt;/EM&gt;OrderItems entity [has all the fields of OrderItems entity and one additional computed field]. It isn't persisted (hence @cds.persistence.skip).&lt;/P&gt;
  &lt;P&gt;The reason for adding it is - it will be eventually used as return type of an unbound function in the OrdersService. The faultCode will be computed in the event handler for the unbound function.&lt;/P&gt;
  &lt;P&gt;At this stage, when I ran &lt;EM&gt;&lt;STRONG&gt;cds build --for java-cf &lt;/STRONG&gt;&lt;/EM&gt;again&lt;EM&gt; &lt;/EM&gt;in terminal, the generated Java class for Orders_ looks like below.&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;package cds.gen.ordersservice;&lt;BR /&gt;...&lt;BR /&gt;@CdsName("OrdersService.Orders")&lt;BR /&gt;public interface Orders_ extends StructuredType&amp;lt;Orders_&amp;gt; {&lt;BR /&gt;  String CDS_NAME = "OrdersService.Orders";&lt;BR /&gt;  ...&lt;BR /&gt;  ServiceItems_ items();&lt;BR /&gt;  ServiceItems_ items(Function&amp;lt;ServiceItems_, CqnPredicate&amp;gt; filter);&lt;BR /&gt;}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;As can be seen above, the return type of &lt;STRONG&gt;items()&lt;/STRONG&gt; in Orders_ has changed to &lt;STRONG&gt;ServiceItems_&lt;/STRONG&gt; (from OrderItems_).&lt;/P&gt;
  &lt;P&gt;Even though nothing was changed nothing with regard to the Orders entity changed, why does the generated Java class for Orders_ change?&lt;/P&gt;
  &lt;P&gt;This later becomes a problem while composing the CqnSelect in the event handler for an unbound function of the service (while trying to populate the value of computed field faultCode).&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 04:08:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cds-sap-cap-for-java-structure-of-generated-java-classes/qaq-p/12538116</guid>
      <dc:creator>rajendra3041-32</dc:creator>
      <dc:date>2022-01-13T04:08:15Z</dc:date>
    </item>
    <item>
      <title>Re: [CDS - SAP CAP for Java] Structure of Generated Java classes</title>
      <link>https://community.sap.com/t5/technology-q-a/cds-sap-cap-for-java-structure-of-generated-java-classes/qaa-p/12538117#M4700436</link>
      <description>&lt;P&gt;The issue is not related to the generated Java code only. &lt;BR /&gt;&lt;BR /&gt;As you define the ServiceItems entity in the OrdersService the OrdersService.Orders.items association is redirected to the OrdersService.ServiceItems entity.&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;See: &lt;A href="https://cap.cloud.sap/docs/cds/cdl#auto-redirect" target="test_blank"&gt;https://cap.cloud.sap/docs/cds/cdl#auto-redirect&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;gt; The new ServiceItems entity &lt;EM&gt;extends &lt;/EM&gt;OrderItems entity [has all the fields of OrderItems entity and one additional computed field]. It isn't persisted (hence @cds.persistence.skip).&lt;/P&gt;&lt;P&gt;&amp;gt; The reason for adding it is - it will be eventually used as return type of an unbound function in the OrdersService. The faultCode will be computed in the event handler for the unbound function.&lt;BR /&gt;&lt;BR /&gt;Please consider to rather define ServiceItems as a type instead to avoid the redirect.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jan 2022 08:34:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cds-sap-cap-for-java-structure-of-generated-java-classes/qaa-p/12538117#M4700436</guid>
      <dc:creator>adrian_goerler</dc:creator>
      <dc:date>2022-01-17T08:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: [CDS - SAP CAP for Java] Structure of Generated Java classes</title>
      <link>https://community.sap.com/t5/technology-q-a/cds-sap-cap-for-java-structure-of-generated-java-classes/qaa-p/12538118#M4700437</link>
      <description>&lt;P&gt;Thanks Adrian. I didn’t realize that auto-redirect would happen here.&lt;/P&gt;&lt;P&gt; &lt;BR /&gt;Since I annotated the ServiceItems entity as  @cds.persistence.skip, I started seeing runtime errors.&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jan 2022 08:46:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/cds-sap-cap-for-java-structure-of-generated-java-classes/qaa-p/12538118#M4700437</guid>
      <dc:creator>rajendra3041-32</dc:creator>
      <dc:date>2022-01-17T08:46:21Z</dc:date>
    </item>
  </channel>
</rss>

