5.8.1. DataManager vs. EntityManager

Both DataManager and EntityManager can be used for operations on entities (CRUD). There are following distinction between these interfaces:

DataManager EntityManager

DataManager is available on both middle and client tiers.

EntityManager is available only on the middle tier.

DataManager is a singleton bean.

You should obtain a reference to EntityManager through the Persistence interface.

DataManager defines a few high-level methods for working with detached entities: load(), loadList(), reload(), commit().

EntityManager mostly resembles the standard javax.persistence.EntityManager.

DataManager always starts new transactions internally.

You have to open a transaction before working with EntityManager.

DataManager loads partial entities according to views.

EntityManager always loads all local attributes. If a view is used, it affects only reference attributes.

DataManager queries can return entities only. Queries for single attributes or aggregates (SUM, COUNT) will fail.

EntityManager can run any JPQL or native queries.

DataManager applies all security restrictions when invoked on the client tier.

EntityManager does not impose security restrictions.

When you work with data on the client tier, you have only one option - DataManager. On the middleware, use EntityManager when you need to implement some atomic logic inside a transaction or run a query returning single attributes or aggregates. Otherwise, on the middleware you can use both.

If you need to overcome restrictions of DataManager when working on the client tier, create your own service and use EntityManager to work with data. In the service, you can check permissions using the Security interface and return data to the client in the form of persistent or non-persistent entities or arbitrary values.