spring-data-neo4j icon indicating copy to clipboard operation
spring-data-neo4j copied to clipboard

findAllById with projection "The query used a deprecated function: `id`."

Open te3ex opened this issue 1 year ago • 5 comments

Hello,

Using Spring data neo4j 7.2.1 having the configuration : withDialect(Dialect.NEO4J_5)

the built in method from repository
ArisClass findAllById(Iterable<String> iterable);
return the correct answer,

but <T> Collection<T> findAllById(Iterable<String> iterable, Class<T> type); return always an empty collection with the log : The query used a deprecated function: id. whatever I put for the type , it happend with a projection as with the domain class.

regards

te3ex avatar Dec 20 '23 10:12 te3ex

That's odd. There should have been a fix in place to avoid the usage of the id function in every case now. Could you provide an example and/or the generated Cypher query and the warning message? The logger for configuration is: org.springframework.data.neo4j.cypher and needs to be set to debug.

meistermeier avatar Dec 20 '23 10:12 meistermeier

from the log I got :

2023-12-20T11:51:29.633+01:00  WARN 11872 --- [nio-8061-exec-1] org.springframework.data.neo4j.cypher    : Neo.ClientNotification.Statement.FeatureDeprecationWarning: This feature is deprecated and will be removed in future versions.
	MATCH (myClass:`my_class`) WHERE id(myClass) = $iterable WITH collect(elementId(myClass)) AS __sn__ RETURN __sn__
```	
my repo is : 

public interface myClassRepository extends Neo4jRepository<myClass, String> {

<T> Collection<T> findAllById(Iterable<String> iterable, Class<T> type);


with this bean created : 
@Bean
Configuration cypherDslConfiguration() {
	return Configuration.newConfig()
			.withDialect(Dialect.NEO4J_5).build();
}

many thanks in advance.


te3ex avatar Dec 20 '23 10:12 te3ex

I assume that you have something in MyClass that looks like this: @Id @GeneratedValue Long id. This would needed to get changed into a String. The elementId is a String with colons like 4:7900ccce-91de-4f45-9742-60769f466719:2 and cannot be converted into a Long.

meistermeier avatar Dec 20 '23 12:12 meistermeier

My domain class is :

@Node("my_class") @Data @NoArgsConstructor @Accessors(chain = true) @EqualsAndHashCode public class MyClass implements IdentifiableClass {

@Id
@GeneratedValue
private String id;

@DynamicLabels
private List<String> labels;

....

And my projection DTO is :

@Data @NoArgsConstructor @EqualsAndHashCode public class MyClassDTOProjection {

private String id;

private List<String> labels;

.....

regards,

te3ex avatar Dec 20 '23 12:12 te3ex

I am fairly new to Neo4J with Springboot and have the exact same issue, for me it happens when using findAll().

This is the error I get:

2024-01-11T21:24:07.046+01:00  WARN 25864 --- [nio-8080-exec-2] o.s.data.neo4j.cypher.deprecation        : Neo.ClientNotification.Statement.FeatureDeprecationWarning: This feature is deprecated and will be removed in future versions.
	MATCH (quiz:`Quiz`) RETURN quiz{.id, .name, __nodeLabels__: labels(quiz), __elementId__: id(quiz)}
	                                                                                                                                                 ^
The query used a deprecated function: `id`.

image

This is everything related to the Quiz Node

🗃 My Classes and Maven

Quiz.java

@Data
@Node("Quiz")
@NoArgsConstructor
@AllArgsConstructor
public class Quiz {

    @Id
    @GeneratedValue(generatorClass = UUIDStringGenerator.class)
    private String id;
    private String name;
}

QuizRepository.java

@Repository
public interface Neo4jQuizRepository extends Neo4jRepository<Quiz, String> {
}

QuizController.java

@RestController
@RequestMapping("/quizzes")
public class QuizController {

    private final QuizService quizService;

    public QuizController(final QuizService quizService) {
        this.quizService = quizService;
    }

    @Observed
    @GetMapping("/all")
    public List<Quiz> getAllQuizzes() {
        return quizService.getAllQuizzes();
    }
}

pom.xml

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-data-neo4j</artifactId>
			<version>3.2.1</version>
		</dependency>

EDIT: FIXED: Realized I forgot @Bean on the cypherDslConfiguration!

Copystrike avatar Jan 11 '24 20:01 Copystrike