diff --git a/src/main/asciidoc/object-mapping/projections.adoc b/src/main/asciidoc/object-mapping/projections.adoc index 5b363cd17..f795639b6 100644 --- a/src/main/asciidoc/object-mapping/projections.adoc +++ b/src/main/asciidoc/object-mapping/projections.adoc @@ -181,9 +181,9 @@ interface TestRepository extends CrudRepository { // <.> List findAllExtendedEntities(); // <.> - List findAllInterfaceProjections(); // <.> + List findAllInterfaceProjectionsBy(); // <.> - List findAllDTOProjections(); // <.> + List findAllDTOProjectionsBy(); // <.> @Query("MATCH (t:TestEntity) - [r:RELATED_TO] -> () RETURN t, COUNT(r) AS numberOfRelations") // <.> List findAllDTOProjectionsWithCustomQuery(); @@ -195,13 +195,15 @@ interface TestRepository extends CrudRepository { // <.> of the extending class. The domain type of the method in question will be the extended class, which still satisfies the domain type of the repository itself <.> This method returns an interface projection, the return type of the method is therefore different - from the repository's domain type. The interface can only access properties defined in the domain type + from the repository's domain type. The interface can only access properties defined in the domain type. + The suffix `By` is needed to make SDN not look for a property called `InterfaceProjections` in the `TestEntity` <.> This method returns a DTO projection. Executing it will cause SDN to issue a warning, as the DTO defines `numberOfRelations` as additional attribute, which is not in the contract of the domain type. The annotated attribute `aProperty` in `TestEntity` will be correctly translated to `a_property` in the query. As above, the return type is different from the repositories' domain type. + The suffix `By` is needed to make SDN not look for a property called `DTOProjections` in the `TestEntity` <.> This method also returns a DTO projection. However, no warning will be issued, as the query contains a fitting - value for the additional attributes defined in the projection. + value for the additional attributes defined in the projection TIP: While the repository in <> uses a concrete return type to define the projection, another variant is the use of <> as explained in the diff --git a/src/test/java/org/springframework/data/neo4j/repository/query/RepositoryQueryTest.java b/src/test/java/org/springframework/data/neo4j/repository/query/RepositoryQueryTest.java index 5fc1f522b..ebf14f096 100644 --- a/src/test/java/org/springframework/data/neo4j/repository/query/RepositoryQueryTest.java +++ b/src/test/java/org/springframework/data/neo4j/repository/query/RepositoryQueryTest.java @@ -490,13 +490,13 @@ final class RepositoryQueryTest { TestEntity.class ), Arguments.of( - "findAllInterfaceProjections", + "findAllInterfaceProjectionsBy", true, TestEntityInterfaceProjection.class, TestEntity.class ), Arguments.of( - "findAllDTOProjections", + "findAllDTOProjectionsBy", true, TestEntityDTOProjection.class, TestEntity.class @@ -602,9 +602,9 @@ final class RepositoryQueryTest { Mono> findAllByNameStartingWith(String name, Pageable pageable); - List findAllInterfaceProjections(); + List findAllInterfaceProjectionsBy(); - List findAllDTOProjections(); + List findAllDTOProjectionsBy(); List findAllExtendedEntities();