0

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?

1 Answers1

0

What you should avoid is passing around entities between different transactions, but passing entities between EJB is not a problem as long as the call happens as part of the same transaction as the call that loads the entity.

To help you further we would need a concrete example of how and especially why you pass entities around between EJB, maybe this is not even necessary in the first place.

Smutje
  • 17,733
  • 4
  • 24
  • 41