Hello,
I am having a situation where sometimes I would like to override the EntityManager (by setting a new one manually) over the one that was injected automatically by Jboss AS,
So I don't use the '@PersistenceContext', but instead I use:
Code:
@PersistenceUnit
private EntityManagerFactory factory;
And factory the entity manager when necessary by: factory.createEntityManager();
Apparently, the behavior is different, as I started to get exceptions such as:
Quote:
A detached entity passed to persist
I assume that somehow the AS is smart enough to inject the right EM even though I use different EJBs for loading/persisting.
Is there a correct way to create entity managers as the AS would do as when using 'PersistenceContext' ? maybe the factory is not the right way here.
Many thanks,
Asaf.