Does anyone know if JBoss @Service EJB’s support transactions? I’d like to work with an EntityManager but am getting “EntityManager must be used within a transaction” errors. Explicitly specifying container-managed transactions and REQUIRED transactions on the EJB doesn’t make a difference.
Thanks.
Update
Here is the code I am using to get an EntityManager:
@PersistenceContext(unitName = "MyPersistenceContextName")
private EntityManager m_entityManager;
And here is the code that failed:
m_entityManager.persist( objectToSave);
m_entityManager.flush();
It failed on the first line.
By applying annotation
@Service, it will install the bean in theMBeanserver with specific name, which runs on a different classloader & your application on another one. Therefore, this may be the reason why MBean not support transaction & not be able to access the context.Instead of interacting with database through MBean, you can delegate it to other EJB bean, which can be accessed through JNDI lookup.