Subodh Joshi
Subodh Joshi

Reputation: 13492

How to maintain org.neo4j.ogm.session.SessionFactory Object

In application we are using OGM only and no SpringBoot or related api ,in our Controller we are using below code

public TopologyExtController( @Context org.neo4j.graphdb.GraphDatabaseService graphDb ) {

if( this.sessionFactory == null )
{
this.sessionFactory = new org.neo4j.ogm.session.SessionFactory(new org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver(graphDb), "com.demo.entity");
}
}

But every time the Controller will be called by request this code also call. Can someone please tell me is this good idea to call above code every time whenever any request comes? Or We should make SessionFactory object Singleton ?

Upvotes: 0

Views: 223

Answers (1)

meistermeier
meistermeier

Reputation: 8262

Sorry, I cannot tell you that this is a good idea ;) Seriously, the SessionFactory should just get created once. When initalizing it, it will scan all you packages for NodeEntitys and RelationshipEntitys and also create the (embedded) driver every time. Make it kind of a singleton to avoid this additional performance costs.

Upvotes: 2

Related Questions