Reputation: 13492
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
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 NodeEntity
s and RelationshipEntity
s and also create the (embedded) driver every time. Make it kind of a singleton to avoid this additional performance costs.
Upvotes: 2