Running query that outputs objects that are not DomainClasses with a bean provided in Spring Boot context

Hi All,

In my use case I need to fetch for data that is not explicitly mapped to a class annotated with
@Node. It seems like there is no method that returns a generic result set (just like in SQL) that could be consumed and mapped to an user's will.

I know that in spring boot context there is Driver bean, that could allow running a query like this, but unfortunately, it creates it's own transaction and that is a thing I would like to to avoid.

So to cut the long story short, is there any class that is aware of current spring boot managed transaction and allows to run a query that doesn't map to a DomainClass.

dependency i use in my project:

org.springframework.boot:spring-boot-starter-data-neo4j:latest

Class in question that almost provides what I want is Neo4jTemplate (but can't execute query with non-DomainClass result type).

Only solution I thought of is to create generic result class node type and use it to wrap around my results e.g create it with appropriate properties and then return it, but it seems too farfetched for me.

Have you looked the Neo4jClient that is part of SDN. It looks like you can map each record to any object with the asList method You provide a mapping function as a parameter. I use this technique when I use the driver.

https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#neo4j-client

2 Likes

thanks, it's all I needed.