Spring Data Neo4j supports projections, meaning you can use DTOs without writing custom Cypher queries.
Instead of a CertificateDTO
class, we create an interface that maps fields automatically:
public interface CertificateProjection {
UUID getId();
String getCommonName();
String getIssuer();
LocalDate getExpiryDate();
boolean isRevoked();
}
Then, modify the repository without writing a custom query:
List<CertificateProjection> findAll();
✔ Spring Data Neo4j automatically maps only these fields.
✔ No need to write Cypher queries manually.
There are cases where custom queries are needed, even though they require extra effort:
Certificate
also loads related nodes like CertificateAuthority
).@Query("MATCH (c:Certificate) WHERE c.revoked = true RETURN c")
List<Certificate> findRevokedCertificates();
✅ Why?