- Direct Known Subclasses:
- JPAAuditLogService
public class JPAService
extends Object
The idea here is that we have a entity manager factory (similar to a session
factory) that we repeatedly use to generate an entity manager (which is a
persistence context) for the specific service command.
To start with, not all of our entities contain LOB's ("Large Objects" see
https://en.wikibooks.org/wiki/Java_Persistence/Basic_Attributes#LOBs.2C_BLOBs
.2C_CLOBs_and_Serialization) which sometimes necessitate the use of tx's even
in read situations.
However, we use transactions here none-the-less, just to be safe. Obviously,
if there is already a running transaction present, we don't do anything to
it.
At the end of every command or operation, make sure to close the entity
manager you've been using -- which also means that you should detach any
entities that might be associated with the entity manager/persistence
context.
After all, this is a service which means our philosophy here is to
provide a real interface, and not a leaky absraction.
(https://en.wikipedia.org/wiki/Leaky_abstraction)