Skip to content

Introduce ProjectingConverter API #2306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mp911de opened this issue Feb 18, 2021 · 0 comments
Open

Introduce ProjectingConverter API #2306

mp911de opened this issue Feb 18, 2021 · 0 comments
Labels
status: pending-design-work Needs design work before any code can be developed

Comments

@mp911de
Copy link
Member

mp911de commented Feb 18, 2021

Spring Data projections can be either interface or DTO projections. In a lot of projects, we use an EntityConverter (EntityReader) to either materialize a backing entity or directly the DTO. The signature of R read(Class<R> targetType, S source) is limiting in the regard that the target type in case of a DTO cannot apply type hints and field name mappings of the underlying persistent entity.

In the case of interfaces, the backing entity must support a partial population which introduces nullability to the actual entity. Especially Kotlin users are required to apply workarounds as Kotlin defaults to non-null behavior.

Ideally, we could introduce a new interface for converters to implement that allows mapping a source object (row, document, …) into a target projection. The projection mapping needs to consider:

  • Target projection type (DTO, interface projection)
  • Underlying entity (to apply type/field name customizations)

Implementation-wise, interface projections could be backed by a Map instead of materializing a partially populated object. In that case, the converter needs to be aware of whether particular properties should be exposed as an actual entity or as nested projection to create the appropriate backing data structure.

Store overview:

  • Neo4j applies some of the field name customizations to their projections (thanks @michael-simons for the discussion)
  • JPA uses constructor/DTO creation and tuple queries to retrieve the correct representation from a query
  • MongoDB, Cassandra, and R2DBC materialize entities for interface projections and read DTO projects directly into the DTO without considering field/column names
@mp911de mp911de added the status: pending-design-work Needs design work before any code can be developed label Feb 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending-design-work Needs design work before any code can be developed
Projects
None yet
Development

No branches or pull requests

1 participant