I'm using Spring 3.1.1 with SDN 7.1.2
I have the "Book" class below as a node. The other classes (for example the "Author" class), are also declared as nodes and have the complementing relationship declarations. There are no properties on the relationships.
In the Author class the following is declared:
@Relationship(type = "writtenBy", direction = INCOMING)
private Set<Book> writtenBy = Collections.emptySet();
However, when I use a query to return a Book Node, and using the Getter (for example on "GetAuthors"), only an empty set is returned. I'm using Lombok and the Getters and Setters seem to be included correctly.
When I check the database with a browser, the relationship is there. Please also see an example from my "BookRepository" interface below:
@Repository
public interface BookRepository extends Neo4jRepository<Book, String> {
Optional<Book> findOneByTitle(String title);
boolean existsByTitle(String title);
@Query("MATCH (book:Book) WHERE book.title = $title RETURN book")
Book findABookManual(@Param("title") String title);
The "findOneByTitle" method is not working properly (it seems to go into a loop there and I don't know why - I have another thread for that). When I use the Manual Query above, the right node is returned pretty fast, however, the sets of the relationships are always empty sets, even when there are relationships in the database. I read that Lombok might not include "toString" methods automatically for fields not in the constructor, so I did the "ToString.Include", however, it does not work, no matter if it's there or not.
As a Book shall only have one Author node, I also tried a relationship declared on a single "Author" object, that just leads to a "null" returned.
import lombok.*;
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Property;
import org.springframework.data.neo4j.core.schema.Relationship;
import java.util.*;
import static org.springframework.data.neo4j.core.schema.Relationship.Direction.INCOMING;
import static org.springframework.data.neo4j.core.schema.Relationship.Direction.OUTGOING;
@Data
@NoArgsConstructor
@ToString
@Node("Book")
public class Book {
@Id
private String title;
@Property("characters")
private List<String>characters;
@Property("genres")
private List<String> genres;
@Property("description")
private String description;
@Property("bookFormat")
private String bookFormat;
@Property("loan")
private boolean loan;
@ToString.Include
@Relationship(type = "published", direction = INCOMING)
private Set<Publisher> publishers = Collections.emptySet();
@ToString.Include
@Relationship(type = "hasFormat", direction = OUTGOING)
private Set<BookFormat> bookFormats = Collections.emptySet();
@ToString.Include
@Relationship(type = "writtenBy", direction = OUTGOING)
private Set<Author> authors = Collections.emptySet();
@ToString.Include
@Relationship(type = "publishedIn", direction = OUTGOING)
private Set<PublishDate> publishDates = Collections.emptySet();
@ToString.Include
@Relationship(type = "hasBorrowed", direction = INCOMING)
private Set<LibraryUser> Borrowers = Collections.emptySet();
public Book (String title, List<String> characters, List<String> genres, String description, String bookFormat, boolean loan) {
this.title = title;
this.characters = characters;
this.genres = genres;
this.description = description;
this.bookFormat = bookFormat;
this.loan = loan;
}