Home » Support » Forum » Entity factory - best practices

Entity factory - best practices

#1

Suppose I run a website that handles services such as user registration, user login checks, etc. I have all the credentials stored in an ObjectDB.

Currently, each time user sends a request, I initiate a db connection by creating entity manager factory from db on disk, get the entity manager, modify stuff, close the connections.

I wonder if it is better to have an overall db manager created on server init, then provide the shared instance over all requests, instead of creating a new one every time.

Out of curiosity, is my current method thread-safe? Can multiple entity managers exist at the same time?

#2

Creating multiple EntityManagerFactory instances is thread safe but inefficient.

It is more efficient to create one EntityManagerFactory per database during the application lifecycle, as demonstrated in the Guest Book web application tutorial.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login