use of org.neo4j.ogm.domain.gh817.Rider in project neo4j-ogm by neo4j.
the class SessionAndMappingContextTest method shouldRefreshUpdatedRelationshipEntities.
// GH-817
@Test
public void shouldRefreshUpdatedRelationshipEntities() {
sessionFactory.openSession().purgeDatabase();
Session sessionForCreation = sessionFactory.openSession();
Rider rider = new Rider("Michael");
Bike bike1 = new Bike("Bike1");
Bike bike2 = new Bike("Bike2");
rider.getTrips().add(new Trip(rider, bike1, "n/a"));
rider.getTrips().add(new Trip(rider, bike2, "n/a"));
try (Transaction tx = sessionForCreation.beginTransaction()) {
sessionForCreation.save(rider);
tx.commit();
}
Session sessionForLoadingAndUpdate = sessionFactory.openSession();
Iterable<Trip> loadedBikes = sessionForLoadingAndUpdate.loadAll(Trip.class);
assertThat(loadedBikes).hasSize(2).extracting(Trip::getName).containsOnly("n/a");
String name = "A nice trip";
Iterable<Trip> updatedBikes = sessionForLoadingAndUpdate.query(Trip.class, "MATCH (r:Rider) - [t:RODE] -> (c:Bike) SET t.name = $newName RETURN *", Collections.singletonMap("newName", name));
Rider loadedRider = sessionForLoadingAndUpdate.load(Rider.class, rider.getId());
assertThat(updatedBikes).hasSize(2).extracting(Trip::getName).containsOnly(name);
assertThat(loadedRider.getTrips()).hasSize(2).extracting(Trip::getName).containsOnly(name);
}
Aggregations