cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How can we update database in spring boot without using repository

Alternative of EntityManager in neo4j is there or not

10 REPLIES 10

What version of Spring Data Neo4j are you running?
Spring Data Neo4j 5 does not provide any other level of abstraction by itself but uses the Neo4j-OGM under the hood (like Spring Data JPA does it with a JPA implementation).
You could opt-in to use the SessionFactory that you can get injected into your classes. If you need any more information about this, feel free to reach out.
Spring Data Neo4j 6 (the project that was named SDN/RX during WIP) provides three levels of abstraction:

  1. Neo4jClient Not aware of any mapping that was done but you could describe it as a Neo4j Driver on steroids. It participates in ongoing Spring transactions, has a fluent API for manual mapping etc.
  2. Neo4jTemplate Uses the metadata from the domain mapping to provide functionality for handling entities. I think this is basically what you are asking for.
  3. Neo4jRepository The third and highest level of abstraction.

Is there any alternative for entity manager in jpa for neo4j in spring data neo4j any idea over that

You did not answer my question which version of Neo4j-OGM or Spring Data Neo4j you are running.

If you do not use anything yet, you should consider using Spring Data Neo4j 6 with all the advantages you get as I have described above.

I am using neo4j-OGM -3.2.17 as I am using spring boot 2.3.5

@gerrit.meier any help over here.

Sorry, I somehow missed the mentioning.
In this case you are running SDN 5 and similar to a JPA EntityManager is the SessionFactory provided by Neo4j-OGM (that works behind SDN 5).
After you created a Session with SessionFactory#openSession you can work with this to load and persist your objects.
It is possible to get a pre-configured SessionFactory and also a Session injected into your classes, if this is the way you want to use it.
Although Sessions participate in the Spring transactions, I advise not to mix up repositories and lower-level Session interaction.
You can read more about the Session usage in the documentation: https://neo4j.com/docs/ogm-manual/current/reference/#reference:session

I actually need it for retrieval queries

We are using criteria builder and criteria query for JPA dynamic query implementation

TypedQuery<? extends ABC> query = em.createQuery(cr);

we are using such a thing

Now I got your question. No, there is no functionality that is equally to the criteria API.
There is something similar and this is the usage of filters with the Session-based queries https://neo4j.com/docs/ogm-manual/current/reference/#reference:filters

Is there any alternative to org.neo4j.ogm.session.Session in SDN 6 so as to run session.query(xyz.class, query, parameters);.

I mean to allow running custom query in SDN 6.

As I already said here How can we update database in spring boot without using repository - #2 by gerrit.meier there are several solutions.
Either Neo4jClient with its query function for custom queries without automatic entity mapping or Neo4jTemplate (e.g. with its findAll method) with a CypherDSL (GitHub - neo4j-contrib/cypher-dsl: A Java DSL for the Cypher Query Language) produced statement.