You're right, I don't need to cast - that was just one of the things I tried, because nothing else worked.
I want two projections, one without related objects (EventList) and one with the first level of relations (EventFull)
So one of the things I tried was your first example:
public interface EventRepository extends Neo4jRepository<Event, Long>, RepositorySortableFilterable<EventList> {
Optional<EventFull> findEventFullById(Long id);
@Query(value = "MATCH (evt:Event)" +
"WHERE toLower(evt.title) CONTAINS toLower($searchTerm) " +
"RETURN evt ORDER BY evt.fullDate ASC SKIP $skip LIMIT $limit",
countQuery = "MATCH (evt:Event) " +
"WHERE toLower(evt.title) CONTAINS toLower($searchTerm) " +
"RETURN count(evt)")
Page<EventList> searchPaginated(String searchTerm, Pageable page);
For getting the list, I do something like this:
List<EventList> = this.eventRepository.searchPaginated(searchTitle, PageRequest.of(query.getPage(), query.getLimit())).stream());
which works just fine.
But when I want to go to the details of one of the events, like this:
Optional<Event> result = eventRepository.findById(idParameter));
this.event = result.orElseThrow(() -> new NoSuchRecordException("Could not find event."));
I only get the event with one-way relations. All other relation-sets are empty.
The same is true if I use the interface EventFull:
@Node("EventFull")
public interface EventFull extends EventProperties {
Set<PersonList> getInvolved();
Set<LocationList> getLocations();
Set<TagList> getTags();
}
Involved and locations are empty, tags are set.
By the way, I also tried this for the list projection:
neo4jTemplate.find(Event.class).as(EventList.class).all().stream().skip(query.getOffset()).limit(query.getPageSize())
This has extremely bad performance.