56
56
import org .springframework .data .neo4j .integration .shared .common .NamesWithSpELCity ;
57
57
import org .springframework .data .neo4j .integration .shared .common .Person ;
58
58
import org .springframework .data .neo4j .integration .shared .common .PersonSummary ;
59
+ import org .springframework .data .neo4j .integration .shared .common .PersonWithNoConstructor ;
59
60
import org .springframework .data .neo4j .integration .shared .common .ProjectionTest1O1 ;
60
61
import org .springframework .data .neo4j .integration .shared .common .ProjectionTestLevel1 ;
61
62
import org .springframework .data .neo4j .integration .shared .common .ProjectionTestRoot ;
@@ -104,6 +105,7 @@ void setup() {
104
105
105
106
transaction .run ("MATCH (n) detach delete n" );
106
107
transaction .
run (
"CREATE (p:PersonEntity {id: 'p1', email: '[email protected] '}) -[:MEMBER_OF]->(department:DepartmentEntity {id: 'd1', name: 'Dep1'}) RETURN p" );
108
+ transaction .run ("CREATE (p:PersonWithNoConstructor {name: 'meistermeier', first_name: 'Gerrit'}) RETURN p" );
107
109
108
110
for (Map .Entry <String , String > person : new Map .Entry [] {
109
111
new AbstractMap .SimpleEntry (FIRST_NAME , LAST_NAME ),
@@ -365,6 +367,34 @@ void projectionsContainingKnownEntitiesShouldWorkFromTemplate(@Autowired Neo4jTe
365
367
.satisfies (ProjectionIT ::projectedEntities );
366
368
}
367
369
370
+ @ Test // GH-2371
371
+ void findWithCustomPropertyNameWorks (@ Autowired PersonWithNoConstructorRepository repository ) {
372
+ assertThat (repository .findAll ()).hasSize (1 );
373
+ ProjectedPersonWithNoConstructor person = repository .findByName ("meistermeier" );
374
+ assertThat (person .getFirstName ()).isEqualTo ("Gerrit" );
375
+ }
376
+
377
+ @ Test // GH-2371
378
+ void saveWithCustomPropertyNameWorks (@ Autowired Neo4jTemplate neo4jTemplate ) {
379
+ PersonWithNoConstructor person = neo4jTemplate .findOne ("MATCH (p:PersonWithNoConstructor {name: 'meistermeier'}) RETURN p" , Collections .emptyMap (),
380
+ PersonWithNoConstructor .class ).get ();
381
+
382
+ person .setName ("rotnroll666" );
383
+ person .setFirstName ("Michael" );
384
+
385
+ neo4jTemplate .saveAs (person , ProjectedPersonWithNoConstructor .class );
386
+
387
+ try (Session session = driver .session (bookmarkCapture .createSessionConfig ())) {
388
+ Record record = session
389
+ .run ("MATCH (p:PersonWithNoConstructor {name: 'rotnroll666'}) RETURN p.name as name, p.first_name as first_name" )
390
+ .single ();
391
+
392
+ assertThat (record .get ("first_name" ).asString ()).isEqualTo ("Michael" );
393
+ }
394
+
395
+ }
396
+
397
+
368
398
private static void projectedEntities (PersonDepartmentQueryResult personAndDepartment ) {
369
399
assertThat (personAndDepartment .getPerson ()).extracting (PersonEntity ::getId ).isEqualTo ("p1" );
370
400
assertThat (
personAndDepartment .
getPerson ()).
extracting (
PersonEntity ::
getEmail ).
isEqualTo (
"[email protected] " );
@@ -382,6 +412,15 @@ private static Statement whoHasFirstName(String firstName) {
382
412
.build ();
383
413
}
384
414
415
+ interface ProjectedPersonWithNoConstructor {
416
+ String getName ();
417
+ String getFirstName ();
418
+ }
419
+
420
+ interface PersonWithNoConstructorRepository extends Neo4jRepository <PersonWithNoConstructor , Long > {
421
+ ProjectedPersonWithNoConstructor findByName (String name );
422
+ }
423
+
385
424
interface ProjectionPersonRepository extends Neo4jRepository <Person , Long >, CypherdslStatementExecutor <Person > {
386
425
387
426
Collection <NamesOnly > findByLastName (String lastName );
0 commit comments