135 words

Entity factory - best practices

#1
2015-06-13 04:58

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?

Flying Banana
Flying Banana's picture
Joined on 2014-06-02
User Post #14
#2
2015-06-14 10:51

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)
support
support's picture
Joined on 2010-05-03
User Post #2,242

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel