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
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
The text was updated successfully, but these errors were encountered:
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 ofR 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:
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:
The text was updated successfully, but these errors were encountered: