Version 5

    EJB3StatelessSessionBean

     

    The remote interface for pass by-value semantics:

    public interface RemoteUsermanagement {
      User updateUser(User user);
    }
    

     

    An optional local interface for pass by-reference semantics:

    public interface LocalUsermanagment {
      updateUser(User user);
    }
    

     

    The implementation

    import javax.ejb.Local;
    import javax.ejb.Remote;
    import javax.annotation.security.RolesAllowed;
    import javax.ejb.Stateless;
    import javax.ejb.TransactionAttribute;
    import javax.ejb.TransactionAttributeType;
    import javax.persistence.EntityManager;
    
    import org.jboss.annotation.security.SecurityDomain;
    
    @SecurityDomain("mydomain")
    @Stateless
    @Remote(RemoteUsermanagement.class)
    @Local(LocalUsermanagement.class)
    public class Usermanagement implements RemoteUsermanagement,
                                           LocalUsermanagement {
    
        @PersistenceContext(unitName="mypersistence")
        protected EntityManager em;
    
        @RolesAllowed("UserAdmin")
        @TransactionAttribute(TransactionAttributeType.REQUIRED)
        public User updateUser(User user) {
            return em.merge(user);
        }
    
        @RolesAllowed("UserAdmin")
        @TransactionAttribute(TransactionAttributeType.REQUIRED)
        public updateUser(User user) {
            user = em.merge(user);
        }
    }