Skip to content

Java: Views and Projections#1916

Merged
renejeglinsky merged 33 commits into
mainfrom
write-through-views
Jul 4, 2025
Merged

Java: Views and Projections#1916
renejeglinsky merged 33 commits into
mainfrom
write-through-views

Conversation

@MattSchur
Copy link
Copy Markdown
Contributor

@MattSchur MattSchur commented Jun 11, 2025

Introduces "Views and Projections" section with

  • Runtime Views
  • Write through Views

and documents some rules for write via path expressions in views.

Also shortens some headers to improve the readability in the navigation bar.

@MattSchur MattSchur requested a review from smahati as a code owner June 11, 2025 16:17
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
@MattSchur MattSchur changed the title Java: Write through Views Java: Views and Projections Jun 12, 2025
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
@MattSchur MattSchur requested a review from vmikhailenko June 12, 2025 15:03
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md
@vmikhailenko
Copy link
Copy Markdown
Contributor

Overall, LGTM. It is nice that we explain this stuff.

@MattSchur MattSchur requested a review from vmikhailenko June 16, 2025 13:39
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md
@MattSchur MattSchur requested a review from agoerler June 27, 2025 15:21
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
@renejeglinsky
Copy link
Copy Markdown
Contributor

@MattSchur Are all comments addressed and can we review and merge?

Comment thread java/working-with-cql/query-execution.md Outdated
Comment on lines +230 to +232
::: tip Prefer simple views
Prefer creating multiple simple views, each tailored to a specific use case, rather than a single complex view that tries to address multiple use cases simultaneously.
:::
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this rather belongs to the best practices

Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md
Comment thread java/working-with-cql/query-execution.md Outdated

To add or update CDS views without redeploying the database schema, annotate them with [@cds.persistence.skip](../../guides/databases#cds-persistence-skip). This tells the CDS compiler to skip generating database views for these CDS views, and the CAP Java runtime resolves them dynamically on each request.

Runtime views must be simple [projections](../../cds/cdl#as-projection-on), not using *aggregations*, *join*, *union* or *subqueries* in the *from* clause, but may have a *where* condition if they are only used to read. On write, the restrictions for [write through views](#updatable-views) apply in the same way as for standard CDS views. However, if a runtime view cannot be resolved, a fallback to database views is not possible, and the statement fails with an error.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runtime views may use only CDS QL, which is supported by the CAP Java runtime. Joins and unions are not supported. We have more restrictions in the "resolve" mode. The "cte" mode is more powerful.

Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
@agoerler
Copy link
Copy Markdown
Contributor

agoerler commented Jul 3, 2025

Maybe an overview table would be helpful to list which "features" can be used with

  • read-only
    • DB views
    • RT views CTE mode
    • RT views resolve mode
  • read/write
    • DB views
    • RT views CTE mode
    • RT views resolve mode

MattSchur and others added 3 commits July 3, 2025 13:04
Co-authored-by: Adrian Görler <adrian.goerler@sap.com>
::: warning Avoid selecting to-many Associations
Do not use [*to-many associations*](../../cds/cdl#to-many-associations) in the select clause of CDS views. This blocks write operations and may cause performance issues due to record duplication on read.
::: tip Prefer simple views
Prefer creating multiple simple views, each tailored to a specific use case, rather than a single complex view that tries to address multiple use cases simultaneously.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> #1957

Copy link
Copy Markdown
Contributor

@agoerler agoerler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Please consider to add some suggestions to https://pages.github.tools.sap/cap/docs/about/best-practices#best-practices-by-cap

(in a different PR)

@MattSchur
Copy link
Copy Markdown
Contributor Author

MattSchur commented Jul 3, 2025

@MattSchur Are all comments addressed and can we review and merge?

@renejeglinsky Yes, please review and merge

Comment on lines +248 to +249
::: warning Avoid Composition Definitions in Views
Avoid [defining](../../cds/cql#association-definitions) new *compositions* in CDS views and prefer *associations* instead, as [deep write](#updatable-views) and [cascading delete](#delete-via-view) are only supported for compositions in persistence entities.
Copy link
Copy Markdown
Contributor

@renejeglinsky renejeglinsky Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::: warning Avoid Composition Definitions in Views
Avoid [defining](../../cds/cql#association-definitions) new *compositions* in CDS views and prefer *associations* instead, as [deep write](#updatable-views) and [cascading delete](#delete-via-view) are only supported for compositions in persistence entities.
::: warning Avoid composition definitions in views
Do not [define](../../cds/cql#association-definitions) *compositions* in CDS views and prefer *associations* instead, to avoid [cascading over associations](#cascading-over-associations).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not about avoiding cascading over associations but deep write and cascade delete are not supported by the runtime for such compositions and would need to be handled by custom code.

Comment thread java/working-with-cql/query-execution.md Outdated
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linting Errors

  • java/working-with-cql/query-execution.md:248:1 container type should be specified [Context: "::: Avoid composition definitions in views"]

Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
Comment thread java/working-with-cql/query-execution.md Outdated
@renejeglinsky renejeglinsky merged commit f7eee25 into main Jul 4, 2025
4 checks passed
@renejeglinsky renejeglinsky deleted the write-through-views branch July 4, 2025 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants