Here are the answers to your questions that I have found in the spec:
[b]5.2.1 Obtaining an Entity Manager in the Java EE Environment[/b]
A container-managed entity manager is obtained by the application through dependency injection, or direct lookup of the entity manager in the JNDI namespace.[/b]
And in the example in this section:
[code]
@PersistenceContext(type=PersistenceContextType.EXTENDED)
EntityManager orderEM;
[/code]
[b]5.2.2 Obtaining an Application-managed Entity Manager[/b]
An application-managed entity manager is obtained by the application from an entity manager factory.
[b]3.3 Persistence Context Lifetime[/b]
By default, the lifetime of the persistence context of a container-managed entity manager corresponds to the scope of a transaction (i.e., it is of type PersistenceContextType.TRANSACTION).
...
The scope of the persistence context of an application-managed entity manager is extended.
[b]5.6.4.2 Container-managed Extended Persistence Context[/b]
[code]
@Stateful
@Transaction(REQUIRES_NEW)
public class ShoppingCartImpl implements ShoppingCart {
@PersistenceContext(type=EXTENDED)
EntityManager em;
[/code]
Now back to your stale data issue - is it a field data or a relationship reference? If it's that latter, it's the user responsibility to maintain the relationships on both sides. Another possible problem would be an update from 2 EMs of the same PK. If in EM1 the only change is in the field 'x' and in EM2 an entity with the same PK is changed in the field 'y', then the update statement to the database will include only the changed columns, but the cached data will have the last committed view of the entity with this PK.
regards,
-marina
[Message sent by forum member 'mvatkina' (mvatkina)]
http://forums.java.net/jive/thread.jspa?messageID=208819