Enable mapping of arbitrary SQL results to aggregate entities #1274
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Update the functionality to support mapping arbitrary SQL results to aggregate entities.
TODO
aggregateHelper
element in theAssociationLinker
annotation toaggregateStrategy
.tableAlias
element to theAssociationLinker
annotation.columnPrefix
element of theAssociationLinker
annotation optional, and set its default value to thetableAlias
value concatenated with an underscore.expand
directive to generate column names and aliases.SelectType.STREAM
andSelectType.COLLECT
.Example
Below is an example that demonstrates the process:
Entity Classes
This example involves three entity classes. The
Department
andEmployee
entities have a bidirectional One-to-Many relationship, while theEmployee
andAddress
entities share a unidirectional One-to-One relationship. Fields representing these relationships are annotated with@Association
.DAO
Pay attention to the
aggregateStrategy
specified in the DAO's@Select
annotation. This strategy class is responsible for linking the entities. Fields in the strategy class annotated with@AssociationLinker
define the relationships usingBiFunction
.propertyPath
: Specify the path from the root entity by chaining property names with dots.columnPrefix
: Specify the prefix for the SQL columns that map to the properties of the associated entity.DepartmentDao.java
SQL
The
columnPrefix
specified in@AssociationLinker
is used to define column aliases in the SQL query.selectById.sql
Client
The DAO can be used in a straightforward manner. By calling the DAO method, you can retrieve an object that includes the aggregated entities.