I develop and application that uses JPA and stateless EJBs. Basically, the application includes EJBs that are responsible for implementing business cases and those responsible for fetching and removing data from the underlying database.
Example:
public interface UserContextAccessEJBLocal {
/**
* Persists the passed instance of {@link UserContex}.
*
* @param userContext an instance of {@link UserContext}
* @throws NullPointerException if userContext is null.
* @throws IOException if an I/O related error occurs.
*/
void remove(UserContext userContext)
throws IOException;}
My question: If a JPA entity is fetched in an EJB A and passed to an EJB B, can I assume that the passed instance belongs to the persistence context managed by the EntityManager that was injected into B or do I have to extract its ID an refetch it?
Is there a difference between stateless and stateful EJBs in regard to my question?