1. User goes to his profile, a JSF page.
2. @RequestScoped CDI bean UserDataB loads the current user of the session at each request, by using @Stateless bean UserC#findUserById(Long id)
3. JSF page's @RequestScoped CDI bean AnotherB loads trades of that user, by using @Stateless bean TradesC#findTradeByClient(User u).
### UserC and TradesC have their own @PersistenceContext EntityManager with the same unitName.
TradesC method needs an User, which is taken from UserDataB CDI. Problem on method execution, which runs a NamedQuery:
com.objectdb.o.UserException - Object 'com.pingushare.entity.p1.User#2' belongs to another EntityManager
Why does this error happen, because there 2 independent transactions? I guess this should be a problem if, in the same transaction, an entity is passed into more EntityManagers, but here are 2 different transactions.
Shouldn't this work? Both @Stateless are method transactional, so each EM should be closed after each method's execution, therefore this error shouldn't appear.