How should one migrate from the removed @Depth annotation in Spring Data Neo4j 6?

Viewed 465

Since spring-data-neo4j 6.0 the @Depth annotation for query methods was removed (DATAGRAPH-1333, commit).

How would one migrate existing 5.3 code which uses the annotation to 6.0? There is no mention of it in the migration guide.

Example usage, documented in the 5.3.6.RELEASE reference:

public interface MovieRepo extends Neo4jRepository<Movie, Long> {
  @Depth(1) // Default, load simple properties and its immediately-related objects 
  Optional<Movie> findById(Long id);

  @Depth(0) // Load simple properties only 
  Optional<Movie> findByProperty1(String property1);

  @Depth(2) // Load simple properties, immediately-related objects and their immediately-related objects
  Optional<Movie> findByProperty2(String property2);

  @Depth(-1) // Load whole relationship graph
  Optional<Movie> findByProperty3(String property3);
}

Are custom queries the only option or is there a replacement?

1 Answers

There is no custom depth anymore in SDN. It either loads everything that is described in your Java model or you have to supply custom Cypher statements.

Some background for this: with SDN 6 we dropped the internal session cache completely because we want to ensure that the Java object graph is after loading and persisting in sync with the database graph. As a consequence we cannot track a custom depth over multiple operations anymore. A partial loaded graph now reflects the truth of the Java model and when getting persisted might remove existing (but not loaded) relationships.

Some insights can be found in the documentation section for the query creation. https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#query-creation

Related