users@glassfish.java.net

Re: obtaining entity manager in entity

From: <glassfish_at_javadesktop.org>
Date: Wed, 26 Sep 2007 17:31:08 PDT

An entity is not a component, so you can't inject a resource into it.

You can always call Persistence.createEMF() and get EMs from it, but you'll need to set some properties that the container is adding for you so that such EM can participate in a JTA transaction (in addition to calling em.joinTransaction()). Which means that if you use the same set of entities in a Java SE environment, your logic will be changed to call em.getTransaction().begin/commit/rollback (and the PU transaction type might change as well).

The entity is intended to represent the state, and the mapping to the database. The business logic (with EM operations) belong to another layer.

Regards,
-marina
[Message sent by forum member 'mvatkina' (mvatkina)]

http://forums.java.net/jive/thread.jspa?messageID=237272